5 ms·
Push: buffer_[head] = value; head_.store(next_head, std::memory_order_release); return true; There's no relationship between the two written variables. Stor
by JonChesterfield 6mo ago
Push:
buffer_[head] = value;
head_.store(next_head, std::memory_order_release);
return true;
There's no relationship between the two written variables. Stores to the two are independent and can be reordered. The aq/rel applies to the index, not to the unrelated non-atomic buffer located near the index.
- loeg 6mo ago> There's no relationship between the two written variables. Stores to the two are independent and can be reordered. The aq/rel applies to the index, not to the unrelated non-atomic buffer located near the index. No, this is incorrect. If you think there's no relationship, you don't understand "release" semantics. https://en.cppreference.com/w/cpp/atomic/memory_order.html https://en.cppreference.com/w/cpp/atomic/memory_order.html > A store operation with this memory order performs the release operation: no reads or writes in the current thread can be reordered after this store.
- JonChesterfield 6mo agoThis was _really_ surprising to me. What's the point of marking individual stores if it affects everything, not just that address. But yeah, what I can find online agrees that C++ has done this. Thanks!
- judofyr 6mo agoThis is just wrong. See https://en.cppreference.com/w/cpp/atomic/memory_order.html https://en.cppreference.com/w/cpp/atomic/memory_order.html. Emphasis mine: > A store operation with this memory order performs the release operation: no reads or writes in the current thread can be reordered after this store. All writes in the current thread are visible in other threads that acquire the same atomic variable (see Release-Acquire ordering below) and writes that carry a dependency into the atomic variable become visible in other threads that consume the same atomic (see Release-Consume ordering below).
- blacklion 6mo agowrite with release semantic cannot be reordered with any other writes, dependent or not. Relaxed atomic writes can be reordered in any way.
- loeg 6mo ago> write with release semantic cannot be reordered with any other writes, dependent or not. To quibble a little bit: later program-order writes CAN be reordered before release writes. But earlier program-order writes may not be reordered after release writes. > Relaxed atomic writes can be reordered in any way. To quibble a little bit: they can't be reordered with other operations on the same variable.
- blacklion 6mo agoYep, you are right, more precise, and precision is very important in this topic. I stand corrected.
- hrmtst93837 6mo ago[flagged]