Reputation: 3369
Quoted from C++ Concurrency in Action $Listing 5.9
A
fetch_sub
operation withmemory_order_acquire
semantics doesn’t synchronize-with anything, even though it stores a value, because it isn’t a release operation. Likewise, a store can’t synchronize-with afetch_or
withmemory_order_release
semantics, because the read part of thefetch_or
isn’t an acquire operation.
It's hard to understand the paragraph above for me. If a fetch_sub
operation with memory_order_acquire
semantics doesn’t synchronize-with anything, why does the interface of fetch_sub
leave a memory order parameter for us as following?
T fetch_sub( T arg, std::memory_order order = std::memory_order_seq_cst ) noexcept;
Upvotes: 4
Views: 341
Reputation: 137425
memory_order_acquire
RMW operation can't synchronize with anything, but a memory_order_release
store synchronizes with a memory_order_acquire
RMW operation that takes the value read from the store. Similarly, while a memory_order_release
store doesn't synchronize with a memory_order_release
RMW, a memory_order_release
RMW can synchronize with a memory_order_acquire
load.memory_order_acq_rel
.Upvotes: 3