2

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:

  • Acquire semantics prevent memory reordering of a read with any read or write operation that follows it in program order;
  • Release semantics prevent memory reordering of a 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?

0

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

See my answer on the linked duplicate, How do memory_order_seq_cst and memory_order_acq_rel differ?, for a more detailed version, including how AArch64 is about as weak as the standard allows, so SC stores can reorder with later operations except for SC loads. Also IRIW reordering.
OP's main question - what is left out by acq_rel that is covered by seq_cst - is very nicely shown by this image preshing.com/images/acq-rel-barriers.png in another of Jeff Preshing's blog posts preshing.com/20120913/acquire-and-release-semantics. Specifically, restrictions on StoreLoad reordering is left out.
2

What is extra is the single total modification order: https://en.cppreference.com/w/cpp/atomic/memory_order#Sequentially-consistent_ordering

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.