A memory barrier is a synchronization operation that prevents the compiler and CPU from moving reads or writes across it in either direction. It belongs to the memory model, which defines permitted memory-access reordering. Acquire operations prevent reads from moving earlier; release operations prevent writes from moving later. section 7.2
Use the ordering guarantees to reason about shared state:
- Acquiring a lock provides acquire semantics and exposes up-to-date memory values. section 7.2
- Releasing a lock provides release semantics and makes changes available to the next thread entering the lock. section 7.2
- For simple multithreading, use locks whenever accessing data shared between threads; lock misuse can still lead to deadlocks. section 7.2
Figure 7.1 Acquire and release semantics
Use the acquire/release diagram to visualize which reads and writes may cross synchronization boundaries. section 7.2


