Software Engineering
What is a TOCTOU race condition?
The name is short for time-of-check to time-of-use. It's what happens when a program checks whether something is true, then acts as if it's still true — but something else changed it in between.
The name, unpacked
Two moments, with a real gap of time between them. The bug lives in the gap.
The parking spot
You checked. You were right, at that moment. But acting on it took time, and the world kept moving during that time.
Why it's called a race
A "race condition" just means the outcome depends on timing that nobody controls.
What isn't a TOCTOU
A real TOCTOU needs both: real elapsed time, and something else able to change the answer during it. A fixed answer read once — even described with "check, then use" words — is missing both.
Why this distinction matters
It's easy to describe ordinary code with race-condition language ("it looked available, then it wasn't") without an actual race existing underneath. The tell: run it again with the exact same input. A real race can come out differently each time. A fixed lookup gives the same answer every time — that's not a race, it's just a decision that was already made.
The fix: make it one step, not two
Locking the spot the instant you check it — instead of checking, then driving over — is what closes the gap.
Sources: "CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition," Common Weakness Enumeration, MITRE Corporation. Longer, more technical version: Reference: TOCTOU Race Condition.