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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ignorant
  • 2,411
  • 4
  • 31
  • 48

2 Answers2

2

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.

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
1

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

Jeff Garrett
  • 5,863
  • 1
  • 13
  • 12