Race Conditions

Concurrency bugs emerge when two or more threads — or clients, or cores — touch shared state without proper synchronization. Every lesson here isolates one interleaving that breaks an assumption.

01
TOCTOU
Time-of-Check to Time-of-Use
L215 MIN
02
DATA RACE
counter++ is three instructions, not one
L215 MIN
03
LOST UPDATE
Two clients, one row, last write wins
L215 MIN
04
CHECK-THEN-ACT
if (!exists) insert — still racy
L212 MIN
05
DEADLOCK
Both holding, both waiting
L215 MIN
06
ABA
Same value, different world
L318 MIN
07
REENTRANCY
The DAO, in miniature
L215 MIN
08
PUBLICATION
Visible before it's ready
L318 MIN
09
LOCKS, ATOMICS, LOCK-FREE
Three ways to make one update safe, three different costs
L215 MIN
10
EVENT LOOP STARVATION
One long task and every other request waits
L112 MIN
11
LIVELOCK & PRIORITY INVERSION
Everyone is busy, nothing gets done
L215 MIN
12
CAPSTONE: CONNECTION POOL
Everything in this path, in one 40-line class
L320 MIN