Module 9: Concurrency
Threads, mutexes, race conditions
Lessons
| ID | Title | Duration |
|---|---|---|
| 9-1 | Threads and pthreads | 30 min |
| 9-2 | Mutexes and Race Conditions | 35 min |
| 9-3 | Condition Variables | 30 min |
| 9-4 | Atomic Operations | 25 min |
| 9-5 | ThreadSanitizer and Debugging Races | 20 min |
Project
| 9-proj | Project: Thread Pool with Work Queue | 75 min |
Key Concepts
PDF Status
- PDF ch10 (Concurrency) — Complete (written 2026-04-08).
- Key Concepts: pthread lifecycle, mutex patterns, condition variable monitor pattern, C11 atomics (
_Atomic/stdatomic.h), deadlock/livelock/priority inversion. - Going Deeper: C11 memory model (happens-before, seq-cst vs acquire/release vs relaxed with worked example), condition variable pitfalls (spurious wakeups, lost wakeup race, broadcast vs signal), lock-free basics (CAS, ABA problem, atomics vs mutex decision table), TSan shadow memory mechanism and report anatomy.
- Real-World Connection: CPython
Python/ceval_gil.c—take_gil/drop_gil, relaxed atomic for drop_request on the hot path, GIL rationale and PEP 703. - Exercises 10.1–10.4 + fully annotated solutions + test files.
- Key Concepts: pthread lifecycle, mutex patterns, condition variable monitor pattern, C11 atomics (