Part 1 · Synchronization primitives
Chapter 1: Mutex
Let one goroutine at a time into the code that touches shared data. How Go's sync.Mutex does it, how it stays fair, and how Linux, Java, C++, Rust and Python make the same trade-offs.
- Taking turnsA bank account that goes negative, and what we need to stop it.2 min
- Break it, then lock itTurn a mutex on in the simulator and see what it fixes and what it costs.3 min
- The idea: mutual exclusionCritical sections, ownership, waiting, and what Unlock promises.3 min
- In Go: reading sync.MutexThe real source: fast path, spinning, queueing, normal and starvation mode.11 min
- In the wildGo, the Linux kernel and Java's ReentrantLock compared, with what their own documents say.6 min
- Other languagesstd::mutex, Rust's Mutex, Python's Lock and Java's ReentrantLock side by side.4 min
- PitfallsForgotten unlocks, copied mutexes, self-deadlock and locks that guard too little.2 min
- Check yourselfQuestions, exercises, and what comes next.2 min