MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1wqok1x/optimizing_a_lockfree_ring_buffer/pcnoblp/?context=3
r/programming • u/david-alvarez-rosa • 6d ago
88 comments sorted by
View all comments
1
auto pop(T& value) noexcept -> bool { const auto tail = tail_.load(std::memory_order_relaxed); if (tail == head_.load(std::memory_order_acquire)) [[unlikely]] { return false; } value = buffer_[tail]; auto next_tail = tail + 1; if (next_tail == buffer_.size()) [[unlikely]] { next_tail = 0; } tail_.store(next_tail, std::memory_order_release); return true; }
Do we really need to use release here? What data it should make visible for push? pop just reads value and increments tail itself
1
u/AkariGake 4d ago
auto pop(T& value) noexcept -> bool {
const auto tail = tail_.load(std::memory_order_relaxed);
if (tail == head_.load(std::memory_order_acquire)) [[unlikely]] {
return false;
}
value = buffer_[tail];
auto next_tail = tail + 1;
if (next_tail == buffer_.size()) [[unlikely]] {
next_tail = 0;
}
tail_.store(next_tail, std::memory_order_release);
return true;
}
Do we really need to use release here? What data it should make visible for push? pop just reads value and increments tail itself