Race Condition

A race condition occurs when program behavior depends on unpredictable timing between concurrent operations.
Also known as
data race

Intuition

Two tasks race to read or write shared state, and the final result changes depending on who gets there first.

Technical definition

A race condition is a correctness bug caused by unsafely ordered access to shared state or resources in concurrent execution.

Example

Two withdrawals processed at the same time may both read the same account balance and overdraw the account.

Common misunderstandings

  • Race conditions can appear even if failures are rare.
  • Testing may miss races because timing is nondeterministic.

Need this inside a product?

The studio builds the systems these terms describe. Tell us what you are working on.