Ignorant
Ignorant

Reputation: 2681

What is the difference between sequential consistency and acquire/release semantics?

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:

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

Answers (2)

Peter Cordes
Peter Cordes

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

Jeff Garrett
Jeff Garrett

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

Related Questions