liveBook · Manning

Race condition

As explained in Think Distributed Systems

A concurrency situation in which at least one possible ordering of actions produces an incorrect result.

A race condition occurs when concurrent actions can be ordered in more than one way and at least one possible ordering produces an incorrect result. Correctness must be defined for the system’s intended outcome. section 1.8 section 2.2

Model each process as a sequence of atomic actions. The concurrent composition of two processes contains every possible interleaving of their actions; a race exists when some interleavings are incorrect. section 1.8

Two proposers and two acceptors

Two proposers broadcast (+2) and (×2) to acceptors initially holding 0. Because these operations are not commutative, applying them in different orders produces different results. The system therefore needs a consistent ordering so both acceptors reach the intended result. section 2.2

Figure 1.19 Reasoning about race conditions
A black background with a black square

AI-generated content may be incorrect.

Visualizes how alternative interleavings create correct or incorrect outcomes. section 1.8

The idea applies beyond threads updating one variable: it covers cooperative or preemptive multitasking, single- or multi-core machines, and multiple machines. Database correctness can require every interleaving to match an equivalent sequential order. section 1.8

How Think Distributed Systems covers it

How deep it goes
Defines races with atomic actions and all interleavings, then demonstrates ordering effects with noncommutative operations.
Examples
Uses atomic-action interleavings and proposers applying (+2) and (×2) to replicated acceptor state.
What it assumes
Assumes only processes, atomic actions, concurrency, and an explicitly chosen notion of correctness.
What you can do after
Evaluate concurrent executions by enumerating possible interleavings and checking whether their results meet the intended correctness condition.
How it connects
Connects race conditions to concurrency, parallelism, event ordering, logical time, commutativity, and serializability.

Also explained in

Compare how 20 books explain race condition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Think Distributed Systems. The section links point to the parts of the book it draws on.