Executing the following is an atomic RMW operation
auto value = atomic.fetch_or(value, order);
When order
is std::memory_order_acq_rel
we know that the load of the previous value in the atomic will acquire any release operations that might have happened previously on the same atomic. And the write will release the current thread's writes for threads that acquire the same atomic variable. Same with std::memory_order_seq_cst
.
But what is the expected behavior of the write part of the RMW operation with respect to memory ordering when you use std::memory_order_acquire
? Similarly, what is the expected behavior of using std::memory_order_release
for the load side of the RMW operation?
order
, unsurprisingly, if that's what you're asking. – Hargreavesmemory_order_release
specify for a read operation? What happens to the read end of a RMW operation when amemory_order_release
is used? – Succentorfetch_or
counts as a write as well. – Hargreavesfetch_or
is one operation, not a separate read and write. If there happens to be an acquire somewhere down the line, then afetch_or
with release semantics will synchronize with that later read. – Hargreaves