Race conditions.
Two people grabbing the last cookie at once because each looked, saw it there, and reached.
- Mine!1
Two people both reach for the one last seat at the very same moment.
- 2
In code: two threads both read the same value, a balance of 100.
- 3
Each subtracts 30 and writes 70 back — so one withdrawal silently disappears.
- After you.4
A lock fixes it: only one thread enters at a time, the other waits its turn.
- You go first… no, you.5
But locks have their own trap — deadlock, where each thread waits for the other forever.
- 6
The cleanest fix is to not share at all: give each thread its own copy.
Semicolony semicolony.dev/eli5/race-conditions/comic