Skip to content

Weak memory models and reordering

Category: Hazards · Status: stub · Lessons: chapter 02, Shared state

One line: CPUs and compilers may perform memory reads and writes in a different order from the source code, and without synchronization another thread can see that order.

Also called: weak ordering, compiler reordering, store buffering.

How it connects

In each language

Rust atomic::Ordering: Relaxed, Release, Acquire, AcqRel and SeqCst choose how strongly each atomic operation synchronizes memory
Go The Go Memory Model ↗ defines happens-before from sequenced-before and synchronized-before, and tells programs to serialize shared access rather than reason about the rest
C++ std::memory_order: atomic operations default to sequentially consistent ordering, which can cost performance
Java JLS §17.4 Memory Model ↗; the java.util.concurrent memory consistency properties ↗ list what happens-before what: unlocking a monitor, volatile writes, Thread.start and join

Where to read more