Locks and Syncing
Race conditions, mutexes, atomics, spinlocks and semaphores.
5 notes · 22 min total
- 1Race Conditions and MutexesWhy unsynchronized read-modify-write corrupts shared data, and how a mutex makes a critical section run one thread at a time.4 min
- 2Atomic OperationsHow hardware instructions like compare-and-swap update one value without a lock, and when you still need a mutex.4 min
- 3SpinlocksWhy a spinlock busy-waits instead of sleeping, when that beats a mutex, and why it only pays off on multi-core machines.6 min
- 4SemaphoresHow a semaphore's counter limits concurrency to N threads, enables signaling, and differs from a mutex because it has no owner.5 min
- 5sleep() vs wait()Why sleep() keeps your locks while wait() releases them, and where yield() fits in.3 min