A race condition occurs when several threads, processes, or nodes access the same resource concurrently and the result depends on the order or timing of their execution. When that order is not controlled, it can corrupt data, lose updates, or deadlock a program. Because race conditions appear rarely and nondeterministically, they are among the hardest defects to reproduce and debug.
They are prevented with synchronization mechanisms such as locks, mutexes, atomic operations, and transactions. In distributed systems, network delays and node failures multiply the possible interleavings, so techniques such as model checking and deterministic simulation testing are also used to uncover them before deployment.