Further reading¶
These references offer introductions, practical examples, and deeper treatments of the topics in this primer.
Many examples use C++ or Rust. They are useful for understanding concurrency, but language and library guarantees differ; use the relevant C and CPython contracts when applying them to interpreter code. Likewise, hardware and Linux kernel ordering rules are not substitutes for the C memory model.
Introductions¶
- Russ Cox, Memory Models. A high-level introduction to the problems memory models address.
- Hans Boehm, A Less Formal Explanation of the Proposed C++ Concurrency Memory Model. An approachable explanation of the fundamental concepts behind the C/C++ memory model, written during its development.
- Mara Bos, Rust Atomics and Locks, chapters 2 (Atomics) and 3 (Memory Ordering). A readable introduction with Rust examples that are useful even if you do not write Rust. Chapter 7 (Understanding the Processor) builds intuition about the hardware layer; it is not a prerequisite for writing correct code.
- ThreadSanitizer, About Data Races. An explanation of data races and why they matter.
Atomics and memory ordering¶
- cppreference,
std::memory_order. A reference for C++ memory orders and their ordering guarantees. - GCC wiki, Memory model synchronization modes. A reference for GCC's atomic synchronization modes.
- Compiler Explorer examples of atomic operations. Compare generated assembly for different memory orders. ARM's weaker hardware memory model often requires different instructions where x86/AMD64 does not; for example, relaxed and acquire loads commonly use the same x86 instruction. Identical assembly does not imply identical language-level guarantees.
Talks¶
- Hans Boehm, Using weakly ordered C++ atomics correctly.
- Fedor Pikus, C++ atomics, from basic to advanced.
- Herb Sutter, atomic Weapons, parts 1 and 2. Talks on the C++ memory model that strongly discourage casual use of relaxed atomics.
Locking and broader parallel programming¶
- Locking in WebKit.
A practical article on lock implementation, also referenced by CPython's
pycore_lock.h. - Paul McKenney, Is Parallel Programming Hard, And, If So, What Can You Do About It?. A substantial book covering topics from problem decomposition to hardware memory models, by a co-inventor of RCU. Best used as a deeper reference rather than read as a prerequisite for the primer.
Hardware ordering and memory barriers¶
These are deeper references for understanding processors and low-level ordering. Keep their hardware or kernel context in mind when reading them.
- Paul McKenney, Memory Barriers: a Hardware View for Software Hackers (PDF).
- Linux kernel, Memory barriers.
- Arm, Barrier Litmus Tests and Cookbook (PDF).