← Lessons

quiz vs the machine

Platinum1850

Concurrency

The Memory Ordering Acquire Release

Pairing acquire and release to publish data safely between threads.

6 min read · advanced · beat Platinum to climb

The Memory Ordering Acquire Release

Modern hardware and compilers reorder memory operations for speed. Acquire release ordering is the disciplined pairing that lets one thread publish data and another consume it without a full barrier.

A release store acts as a one way fence. Any writes a thread performed before the release become visible to another thread that later does an acquire on the same variable. Nothing before the release can move after it.

An acquire load is the matching one way fence in the other direction. Once a thread acquires, it is guaranteed to see everything the releasing thread wrote before its release. Nothing after the acquire can move before it.

  • Publish and consume Writer fills data, then does a release store of a flag, reader does an acquire load of the flag, then reads the data safely.
  • Cheaper than sequential consistency It constrains only the needed direction, not a global total order.
  • Must be paired A release with no matching acquire, or the wrong variable, gives no guarantee.

The mental model is a gate. Release closes the gate behind your writes so they are flushed, acquire opens the gate ahead so you see them. This is the core of safe lock free handoff.

Key idea

A release store publishes prior writes and a matching acquire load consumes them, giving safe ordered handoff without a full memory barrier.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a release store guarantee?

2. Why must acquire and release be paired on the same variable?