Concurrency Mind Map

Algorithm & Systems Visualizations

Every concurrency visualization on this site on one map. The branches are the main ideas. Each leaf is a page; the grey line under it is the one thing to remember about it. Click a branch to focus on it, click a page to open it.

Recall mode hides the page names. Read the hint, say the name, then click the "?" to check.

1. How the map is organized

Overview of the concurrency mind map: Concurrency basics, Atomics and spinning, Locks that sleep, Waiting for a condition, Classic problems, Many tasks, few threads.
The map at a glance: 6 branches, 25 pages.

Ask what a thread does while it cannot go on, and you know the branch:

  • It keeps the CPU and retries with one atomic instruction: atomics and spinning.
  • It sleeps until the lock is free: locks that sleep. It sleeps until some state changes (an item, a permit): waiting for a condition.
  • It is not an OS thread at all but a task, coroutine or goroutine that a runtime parks: many tasks, few threads.
  • The classic problems combine these tools; basics explains why any of it is needed.

2. The branches side by side

BranchA waiting thread...Main toolClassic bug
Concurrency basicstakes turns on a coretime slicing, corescounter++ race
Atomics and spinningspins on the CPUxchg, cmpxchgwasted CPU, ABA
Locks that sleepsleeps in the kernelfutexdeadlock
Waiting for a conditionsleeps until signalledsemaphore, condition variablelost wake-up
Classic problemsdepends on the solutionall of the abovedeadlock, starvation
Many tasks, few threadsis parked by a runtimerun queues, work stealingblocking call stalls a thread

3. Five facts to remember

  • A data race needs shared data, at least one writer and nothing ordering the accesses.
  • counter++ is a read, an add and a write, so two threads can lose an update.
  • Deadlock needs all four Coffman conditions; break one, for example with a fixed lock order, and it cannot happen.
  • Always wait on a condition variable in a while loop: a wake-up can be spurious or already stale.
  • Spinning pays only when the wait is shorter than the cost of sleeping and waking up.

See all concurrency pages in the index, or the other mind maps.