# 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](https://research.swtch.com/mm).
  A high-level introduction to the problems memory models address.
- Hans Boehm, [A Less Formal Explanation of the Proposed C++ Concurrency Memory Model](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1276.htm).
  An approachable explanation of the fundamental concepts behind the C/C++
  memory model, written during its development.
- Mara Bos, [Rust Atomics and Locks](https://marabos.nl/atomics/),
  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](https://github.com/google/sanitizers/wiki/ThreadSanitizerAboutRaces).
  An explanation of data races and why they matter.

## Atomics and memory ordering

- cppreference, [`std::memory_order`](https://en.cppreference.com/w/cpp/atomic/memory_order).
  A reference for C++ memory orders and their ordering guarantees.
- GCC wiki, [Memory model synchronization modes](https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync).
  A reference for GCC's atomic synchronization modes.
- [Compiler Explorer examples of atomic operations](https://godbolt.org/z/zqeEWq44f).
  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](https://youtu.be/M15UKpNlpeM).
- Fedor Pikus, [C++ atomics, from basic to advanced](https://www.youtube.com/watch?v=ZQFzMfHIxng).
- 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](https://webkit.org/blog/6161/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?](https://www.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html).
  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](http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2010.06.07c.pdf) (PDF).
- Linux kernel, [Memory barriers](https://www.kernel.org/doc/Documentation/memory-barriers.txt).
- Arm, [Barrier Litmus Tests and Cookbook](http://infocenter.arm.com/help/topic/com.arm.doc.genc007826/Barrier_Litmus_Tests_and_Cookbook_A08.pdf) (PDF).

---

[Back to primer](index.md) · [Contents and topic index](contents.md)
