Fundamentals
Set theme to dark (⇧+D)

Race Condition

A Race Condition is one where a system’s substantive behavior is dependent on the sequence or timing of other controllable events. It becomes a bug when one or more of those behaviors is undesirable.

A Race Condition is usually seen when multiple threads operate on a shared state without proper locking.

A good example is where one thread increases a value and the other decreases it. If one starts with 0, and both threads run once, you expect 0 as the output. But in a race condition that doesn’t have to be the case:

Thread 1Thread 2Value
0
read <- 00
read <- 00
increase -> 10
decrease -> -10
write1
write-1

A special kind of Race Condition is the Racetrack Problem.