内存屏障和内存模型 | SF-Zhou's Blog #167
SF-Zhou
announced in
Announcements
Replies: 2 comments 2 replies
-
如果你写的代码只在 x86 上执行,那么除了 |
Beta Was this translation helpful? Give feedback.
0 replies
-
大佬请教一下,mc可以这样写吗 int PopByMutiThread(std::unique_ptr<T>* item, int retry_time = 5) {
for (int i = 0; i < retry_time || retry_time == -1; i++) {
uint64_t h = head_.load();
uint64_t t = tail_.load();
if (t == h) {
return kEmpty;
}
if (tail_.compare_exchange_strong(t, t + 1)) {
auto& pop = items_[t % capacity_];
if (pop == nullptr) {
return kConflict;
}
*item = std::move(pop);
// tail_.fetch_add(1);
return 0;
}
}
return kInvalid;
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://sf-zhou.github.io/programming/memory_barrier.html
Beta Was this translation helpful? Give feedback.
All reactions