Reputation: 2681
As far as I know, acquire/release semantics act as a middle ground between sequential consistency and the unconditional memory reordering freedom allowed by a weaker memory model (or "relaxed", as C++ calls it). In a nutshell:
read
with any read
or write
operation that follows it in program order;write
with any read
or write
operation that precedes it in program order.Cool. But those guarantees, combined together, look like sequential consistency to me. What does sequential consistency provide that acquire/release semantics together don't? Could you give an example?
Upvotes: 2
Views: 961
Reputation: 365517
In hardware terms, acq/rel allows a store/reload within one thread to store-forward the value from the store buffer before it becomes globally visible to other threads.
seq_cst forces the store buffer to drain before a seq_cst load can reload a seq_cst store from the same thread. (Or before a seq_cst load can read cache if it's not a reload of a recent store.) There can't be any in-flight seq_cst stores from this core when a seq_cst load reads a value from cache; they must all be globally visible.
This is the difference for https://preshing.com/20120515/memory-reordering-caught-in-the-act/ - adding a full memory barrier between the store and reload is what's needed (on x86) to go from acq_rel to seq_cst.
Upvotes: 3
Reputation: 7518
What is extra is the single total modification order: https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering
Upvotes: 2