📖 Book · multithreading · high
🧭 Memory ordering & atomics, deep dive
The C++ memory model from first principles — relaxed, acquire/release, acq_rel, seq_cst, fences. Every demo runs.
A from-first-principles deep dive into the C++ memory model: why the compiler and CPU reorder memory operations, the six memory_order values, the acquire/release happens-before pair that powers every lock and lock-free queue, acq_rel for read-modify-write / CAS, why seq_cst is the safe default and what it costs, standalone atomic_thread_fence, is_lock_free, and a practical decision table for choosing the weakest correct ordering. Every demo is correctly synchronized and runs in the browser; the relaxed-signaling anti-pattern is shown but never executed.
What this book covers
- 01Why memory ordering exists at all
- 02relaxed — atomicity without ordering
- 03acquire / release — the synchronization pair
- 04acq_rel & RMW — CAS, fetch_add, lock-free
- 05seq_cst — the single total order (and its cost)
- 06Fences — ordering without tagging an operation
- 07Lock-free fine print + a decision table
Read it in full — runnable C++ + step-through animations
Every chapter of Memory ordering & atomics, deep dive ships complete, editable code you compile and run in the browser, plus the same in-depth animations as the lessons.