A race condition is a bug where the result depends on the unpredictable timing of concurrent operations accessing shared state. The classic case is a read-modify-write that isn't atomic.
How it works
counter += 1 looks atomic but is really three steps: read, add, write. Two threads can interleave so an update is lost.
counter = 0
Thread A: read 0 ─────────── write 1
Thread B: read 0 ─ write 1
Result: 1 (should be 2 — one increment lost)
