Race Condition
Subject: Computer and Technology noun /ˈreɪs kənˌdɪʃ.ən/ 1 definition
- concurrent-computing
- thread-synchronization
- operating-systems
- distributed-systems
-
Definition (noun)
Entry #40 · UpdatedA Race Condition is a flaw in a software or digital hardware system where the correctness of the outcome depends on the uncontrolled timing, scheduling, or sequence of two or more concurrent operations. When parallel threads, distributed requests, or electrical signals interact with shared state without proper coordination, variations in CPU scheduling, network latency, or propagation delay can interleave their steps in unintended ways—leading to lost updates, corrupted data, or bypassed invariant checks that manifest intermittently and resist simple debugging. Unlike a deadlock, which freezes execution while tasks wait indefinitely on one another, a race condition lets execution continue into an invalid state; it also differs from a strict data race in that ordering hazards can arise across coordinated operations even when individual memory reads and writes are atomic.
Common Types
Data Race: Occurs when two or more threads concurrently access the same memory location without synchronization, and at least one access is a write, risking torn reads, lost writes, or undefined behavior.
Read-Modify-Write Race: Happens when concurrent tasks independently read a shared value, compute an update locally, and write back results without an atomic transaction or lock, causing later writes to silently overwrite earlier updates.
Time-of-Check to Time-of-Use (TOCTOU): Arises when a program validates a resource's state—such as file permissions or an entitlement—before acting on it, allowing an intervening process or attacker to modify the state in between.
Digital Logic Race: Occurs in asynchronous hardware circuits when changing inputs traverse logic paths with unequal gate or wire propagation delays, creating transient output glitches or latching an unintended stable state.
Example
Suppose an online ticketing backend shows 1 seat remaining on a flight when two customers submit checkout requests simultaneously without database row locking or an atomic decrement. Both worker threads read
seats_available == 1, pass the availability check before either commits, and write back0, confirming two separate reservations for the single seat.