Concurrency & Parallelism

How do multiple pieces of work make progress safely, how do we coordinate shared state, how do we use multiple cores effectively, and why do concurrent systems fail in ways that testing does not catch?

Your path through Concurrency & Parallelism

0 of 42 Foundation lessons done
0 of 154 lessons done overall
Start: What Concurrency Actually Is →

Then follow the stages in order

Each stage builds on the ones before it. Labs and simulators sit right after the lessons they exercise. Open a stage to see its lessons. Full roadmap with goals →

  1. Concurrency, parallelism, tasks and threads0 of 16 lessons done
    1. What Concurrency Actually IsFoundation≈ 15 min
    2. Which One Does This Workload Need?Foundation≈ 15 min
    3. Why Concurrency Exists: WaitingFoundation≈ 15 min
    4. Why Parallelism Exists: ComputeFoundation≈ 15 min
    5. Classifying the Work: Computing or Waiting?Foundation≈ 15 min
    6. Choosing an Execution ModelFoundation≈ 15 min
    7. What "Making Progress" Actually MeansFoundation≈ 15 min
    8. Concurrency Is Always Bought With ComplexityFoundation≈ 20 min
    9. Processes: Isolation You Cannot Accidentally BreakFoundation≈ 15 min
    10. Threads: One Address Space, Several Instruction StreamsFoundation≈ 20 min
    11. Thread or Process?Foundation≈ 15 min
    12. A Task Is Not a ThreadFoundation≈ 15 min
    13. Coroutines: Functions That Can PauseFoundation≈ 15 min
    14. Python: Threads, Processes and the GILFoundation≈ 20 min
    15. JavaScript: One Event Loop per Agent, Not One Thread per RuntimeFoundation≈ 20 min
    16. C++: Threads, Atomics and a Memory Model With TeethFoundation≈ 20 min
  2. Shared state, races and critical sections0 of 15 lessons done
    1. Shared Mutable StateFoundation≈ 15 min
    2. Interleavings: The Schedule Is Part of the ProgramFoundation≈ 20 min
    3. Invariants: Name It Before You Lock ItFoundation≈ 15 min
    4. Finding the Critical SectionFoundation≈ 20 min
    5. Reasoning About Races: A Method, Not an InstinctFoundation≈ 20 min
    6. Data Race Is Not Race ConditionFoundation≈ 20 min
    7. The Atomicity IllusionFoundation≈ 20 min
    8. Nondeterminism: Same Input, Different OutputFoundation≈ 15 min
    9. Immutability as a Concurrency StrategyFoundation≈ 15 min
    10. Copy or Share?Foundation≈ 10 min
    11. Copy-on-Write as a Concurrency StrategyFoundation≈ 15 min
    12. Optimistic Concurrency ControlFoundation≈ 20 min
    13. Pessimistic ConcurrencyFoundation≈ 15 min
    14. Optimistic vs PessimisticFoundation≈ 15 min
    15. Initialization RacesFoundation≈ 20 min
  3. Mutexes, semaphores and condition variables0 of 11 lessons done
    1. Mutexes: What They Protect and What They Do NotFoundation≈ 20 min
    2. Lock Scope: What You Hold It AcrossFoundation≈ 20 min
    3. Read/Write Locks, HonestlyFoundation≈ 20 min
    4. Semaphores: Counting Permits as a Resource LimitFoundation≈ 20 min
    5. Semaphore versus Mutex: Not the Same PrimitiveFoundation≈ 20 min
    6. Condition Variables: Waiting Until a Predicate Is TrueFoundation≈ 20 min
    7. Lost Wakeups: The Notify That Arrived Before the WaitFoundation≈ 20 min
    8. Spurious Wakeups: Why It Is `while`, Not `if`Foundation≈ 20 min
    9. Spin LocksFoundation≈ 20 min
    10. What "Thread-Safe" Actually MeansFoundation≈ 20 min
    11. ReentrancyFoundation≈ 15 min
  4. Async, promises, coroutines and event loops0 of 16 lessons done
    1. Event Loops as a Concurrency ModelIntermediate≈ 15 min
    2. Await Is a Yield PointIntermediate≈ 15 min
    3. Futures & PromisesIntermediate≈ 15 min
    4. Worker ThreadsIntermediate≈ 15 min
    5. Web WorkersIntermediate≈ 15 min
    6. Event Loop or Threads?Intermediate≈ 20 min
    7. Async Is Not ParallelismIntermediate≈ 15 min
    8. Blocking the Event LoopIntermediate≈ 20 min
    9. Promise.all & gatherIntermediate≈ 20 min
    10. The Sequential Await TrapIntermediate≈ 20 min
    11. Structured ConcurrencyIntermediate≈ 15 min
    12. CancellationIntermediate≈ 20 min
    13. Cancellation PropagationIntermediate≈ 20 min
    14. TimeoutsIntermediate≈ 15 min
    15. Deadlines vs TimeoutsIntermediate≈ 15 min
    16. Orphaned TasksIntermediate≈ 15 min
  5. Thread pools, worker pools, producer/consumer and backpressure0 of 17 lessons done
    1. Producer / ConsumerIntermediate≈ 15 min
    2. Bounded vs Unbounded QueuesIntermediate≈ 20 min
    3. BackpressureIntermediate≈ 15 min
    4. ChannelsIntermediate≈ 15 min
    5. Message PassingIntermediate≈ 15 min
    6. The Actor ModelIntermediate≈ 15 min
    7. Concurrent QueuesIntermediate≈ 15 min
    8. Draining a PipelineIntermediate≈ 15 min
    9. Thread PoolsIntermediate≈ 15 min
    10. Sizing a Thread PoolIntermediate≈ 15 min
    11. Worker Pools Beyond ThreadsIntermediate≈ 15 min
    12. Work StealingIntermediate≈ 15 min
    13. Pool SaturationIntermediate≈ 20 min
    14. Bounding ConcurrencyIntermediate≈ 20 min
    15. Unbounded ConcurrencyIntermediate≈ 20 min
    16. Thundering HerdIntermediate≈ 20 min
    17. Single-Flight CoalescingIntermediate≈ 20 min
  6. Deadlocks, starvation, livelock and contention0 of 15 lessons done
    1. DeadlockIntermediate≈ 20 min
    2. The Four ConditionsIntermediate≈ 15 min
    3. Preventing DeadlockIntermediate≈ 15 min
    4. Lock OrderingIntermediate≈ 20 min
    5. LivelockIntermediate≈ 15 min
    6. StarvationIntermediate≈ 15 min
    7. FairnessIntermediate≈ 15 min
    8. Priority InversionIntermediate≈ 15 min
    9. What Contention Actually CostsIntermediate≈ 20 min
    10. Lock ConvoysIntermediate≈ 15 min
    11. False ParallelismIntermediate≈ 15 min
    12. OversubscriptionIntermediate≈ 20 min
    13. The Cost of a Context SwitchIntermediate≈ 15 min
    14. More Threads Is Not More SpeedIntermediate≈ 15 min
    15. Busy WaitingIntermediate≈ 20 min
  7. Atomics, memory ordering and lock-free0 of 15 lessons done
    1. Atomics: What Is Actually IndivisibleAdvanced≈ 20 min
    2. Compare-and-Swap and the Retry LoopAdvanced≈ 15 min
    3. Atomics Are Not MagicAdvanced≈ 15 min
    4. Lock-Free Is a Progress GuaranteeAdvanced≈ 15 min
    5. A Lock-Free Stack, and What the Teaching Version OmitsAdvanced≈ 20 min
    6. Wait-Free vs Lock-Free: Whose Progress Is GuaranteedAdvanced≈ 15 min
    7. The ABA Problem: The Value Came BackAdvanced≈ 15 min
    8. What a Memory Model DefinesAdvanced≈ 20 min
    9. Happens-Before: The Edge That Makes a Write VisibleAdvanced≈ 15 min
    10. Reordering: The Compiler and the CPU Both Do ItAdvanced≈ 15 min
    11. Memory Barriers Constrain Ordering, Not CachesAdvanced≈ 15 min
    12. False Sharing: Different Variables, Same Cache LineAdvanced≈ 15 min
    13. What a Shared Write CostsAdvanced≈ 15 min
    14. Safe Publication: Handing Over a Finished ObjectAdvanced≈ 20 min
    15. Double-Checked Locking: The Canonical Cautionary TaleAdvanced≈ 20 min
  8. Parallel algorithms, fork/join and SIMD0 of 18 lessons done
    1. Fork/JoinAdvanced≈ 20 min
    2. Parallel ReduceAdvanced≈ 20 min
    3. The Map/Reduce PatternAdvanced≈ 20 min
    4. Parallel AlgorithmsAdvanced≈ 20 min
    5. Parallel OverheadAdvanced≈ 15 min
    6. Amdahl's LawAdvanced≈ 20 min
    7. Gustafson's LawAdvanced≈ 20 min
    8. Work and SpanAdvanced≈ 20 min
    9. Dependency GraphsAdvanced≈ 20 min
    10. SIMD: One Instruction, Many ElementsAdvanced≈ 15 min
    11. Task Parallelism vs Data ParallelismAdvanced≈ 15 min
    12. GPU Parallelism: Thousands of Lanes, One BusAdvanced≈ 15 min
    13. Pipeline Parallelism: Different Items, Different StagesAdvanced≈ 20 min
    14. Fan-Out / Fan-In: One Request Becomes NAdvanced≈ 15 min
    15. Scatter/Gather and the Tail You InheritAdvanced≈ 20 min
    16. BarriersAdvanced≈ 20 min
    17. Latches & CountdownsAdvanced≈ 20 min
    18. Parallelism Moves the Load DownstreamAdvanced≈ 20 min
  9. Parallel performance, debugging and production concurrency0 of 31 lessons done
    1. Why Eight Cores Give You Four and a HalfAdvanced≈ 15 min
    2. Memory Bandwidth: More Cores, Same BusAdvanced≈ 15 min
    3. Parallelism Can Destroy LocalityAdvanced≈ 15 min
    4. NUMA: Not All Memory Costs the SameAdvanced≈ 15 min
    5. Thread Affinity: Pinning, and What It Costs YouAdvanced≈ 15 min
    6. Reduction Ordering: The Sum Changed When the Worker Count DidAdvanced≈ 15 min
    7. Determinism: Same Input, Same Output?Advanced≈ 15 min
    8. Ordering Guarantees: Four Levels, Four PricesAdvanced≈ 15 min
    9. What to Instrument in a Concurrent SystemAdvanced≈ 10 min
    10. Hold Time, Wait Time, and the Ratio Between ThemAdvanced≈ 10 min
    11. Reading a Thread DumpAdvanced≈ 15 min
    12. Task Dumps: When the Threads Look Idle and Nothing Is MovingAdvanced≈ 10 min
    13. Off-CPU Time: The Thing a CPU Profiler Cannot SeeAdvanced≈ 10 min
    14. Race Detectors: What They Find, and What They Structurally CannotAdvanced≈ 15 min
    15. Heisenbugs: The Bug That Leaves When You Look at ItAdvanced≈ 10 min
    16. Deterministic Replay: Making the Schedule ReproducibleAdvanced≈ 15 min
    17. Stress Testing: A Test That Passed Once Proves NothingAdvanced≈ 15 min
    18. Choosing a Concurrency Model for a ServerAdvanced≈ 15 min
    19. Thread per Request: The Model That Reads Like Ordinary CodeAdvanced≈ 15 min
    20. Event-Driven Servers: Many Connections, One LoopAdvanced≈ 10 min
    21. Hybrid Runtimes: It Was Never Threads Versus AsyncAdvanced≈ 10 min
    22. UI Concurrency: One Thread Owns the ScreenAdvanced≈ 15 min
    23. The Database Solves Concurrency For Its Data, Not For Your MemoryAdvanced≈ 15 min
    24. What Changes When the Shared State Is on Another MachineAdvanced≈ 15 min
    25. A Mutex on Server A Does Nothing About Server BAdvanced≈ 15 min
    26. The Concurrency Pattern CatalogueAdvanced≈ 20 min
    27. Concurrency Anti-PatternsAdvanced≈ 20 min
    28. Can These Tool Calls Run At the Same Time?Advanced≈ 10 min
    29. Parallel Tool Calls: Lower Latency, and Four BillsAdvanced≈ 15 min
    30. Two Agents, One DocumentAdvanced≈ 15 min
    31. Cancelling an Agent Run: What Actually StopsAdvanced≈ 15 min

What work are you trying to run?

The execution model is derived from the work, not chosen from a catalogue. Pick the work and the first question is about the work — never about a primitive.

The first question to ask

Is every core already busy, or is one core busy and seven idle — and do you know which?

  1. 1Classifying the Work: Computing or Waiting?Before you can choose an execution model you have to know what the work is doing with the wall clock. Compression, resizing, encryption, parsing and numerics compute. Network calls, database queries, disk reads and third-party APIs wait. Most real handlers do both, in phases, and the phases want different models.
  2. 2Why Parallelism Exists: ComputeOne billion floats to sum. One core does it in 400 ms. Four cores should do it in 100 ms and will actually do it in about 130. Parallelism exists because a single core stopped getting faster around 2005 and the only remaining lever was more of them.
  3. 3Choosing an Execution ModelSeven questions — bound, sharing, independence, ordering, task count, duration, isolation — and seven answers: sequential, threads, processes, async, worker pool, message passing, parallel algorithm. Every answer comes with why it wins, what it costs and how it fails, because a recommendation without those three is a preference.
  4. 4Fork/JoinSplit the work, run the pieces, wait for all of them, combine. The split is easy and the combine is arithmetic — the join is the part that carries the correctness, because it is the only place a happens-before edge exists between the children and the parent that reads their results.
  5. 5Parallel OverheadSplitting, scheduling, synchronizing and combining are work the sequential version never does. For small tasks that overhead exceeds the task, and the parallel version is measurably slower on more hardware — which is why every parallel decomposition needs a size below which it stops decomposing.
  6. 6Amdahl's LawThe part that cannot be parallelised sets a ceiling on everything else. If a tenth of the job must happen in sequence, an infinite number of cores still cannot make it more than ten times faster — and long before infinity, each extra core is buying almost nothing.

The learning loop

Every lesson answers this chain as explicit fields — including the two that are never optional here: what invariant must hold under every interleaving, and what complexity the concurrency cost you.

Work→Can it overlap?→Can it parallelise?→What is shared?→What ordering?→What synchronization?→Where is contention?→What can deadlock?→What can race?→What is gained?→What complexity?

Flagship experiences

Learning modules

154 lessons
Concurrency Fundamentals8

Should this work overlap, run simultaneously, or neither?

The distinction the whole domain rests on: overlapping progress versus simultaneous execution, why each exists, how to classify work as waiting-bound or compute-bound, and the honest admission that concurrency is always bought with complexity.

Processes, Threads & Tasks8

What unit actually carries this work, and who schedules it?

Processes, threads, tasks and coroutines as distinct things a runtime can hand you — and the language-specific reality of what each one buys in C++, JavaScript and CPython. The kernel-side mechanics live in Operating Systems.

Async & Event Loops8

What does suspending a task actually do, and what still runs?

Async/await as an execution model rather than syntax: futures and promises, the event loop, worker threads and web workers, and the two lessons that matter most — async is not parallelism, and a CPU-bound handler stalls the loop for everyone.

Shared State & Races8

What is shared, what must stay true, and which schedule breaks it?

The core of the domain. Shared mutable state, invariants, finding the minimal critical section, enumerating interleavings to locate a failing schedule, and the distinction between a race condition and a data race that most engineers conflate.

Synchronization Primitives8

Which guarantee does this primitive give, and which does it not?

Mutexes and the scope you put them around, read/write locks, semaphores as permit counters, condition variables and the predicate loop — with lost and spurious wakeups as the failures that follow from getting the loop wrong.

Queues, Channels & Message Passing8

Can we avoid sharing state by moving data instead?

Producer/consumer as the flagship pattern, bounded versus unbounded queues, backpressure as the conversation between a fast producer and a slow consumer, channels, message passing and the actor model — coordination without shared memory.

Deadlock, Livelock & Starvation8

How does a correct-looking system stop making progress?

The four conditions for deadlock and how to break each one, lock ordering as the practical answer, wait-for graphs and their cycles, livelock where everyone is busy and nothing advances, starvation, fairness and priority inversion.

Contention & Oversubscription7

Why did adding threads make it slower?

Eight cores all waiting on one lock. Convoys, false parallelism, oversubscription, the real cost of a context switch, and busy waiting — the module that explains why parallel hardware does not imply parallel throughput.

Atomics & Lock-Free7

What does an atomic operation actually make indivisible?

Atomic reads, writes and compare-and-swap, why an atomic variable does not make a multi-step invariant safe, and lock-free concepts treated honestly as progress guarantees rather than performance promises — CAS loops, the ABA problem, wait-free versus lock-free.

Memory Models & Visibility8

Will the other thread even see what I wrote?

The advanced core: threads do not necessarily observe memory operations in source order. Happens-before, compiler and CPU reordering, barriers, false sharing, cache coherence traffic, safe publication and why double-checked locking is the canonical cautionary tale.

Thread & Worker Pools6

How many workers, and what happens to the work that does not fit?

Pools as bounded resource use rather than unlimited spawning, the reasoning behind sizing (and the refusal to give a universal formula), work stealing, saturation, and bounding concurrency as a first-class design decision.

Parallel Decomposition9

Which parts of this computation are independent, and what limits the speedup?

Fork/join, parallel reduce, map/reduce as a computational pattern, the overhead that makes parallelising small work slower, Amdahl and Gustafson as complementary intuitions, and work versus span as the real ceiling on a dependency graph.

Data & Pipeline Parallelism6

Is the same operation applied to many items, or different operations at once?

SIMD and data parallelism against task parallelism, pipeline stages that let items occupy different stages simultaneously, fan-out/fan-in, scatter/gather and the tail-latency cost of waiting for the slowest branch.

Coordination & Limits7

How do independent tasks agree on when to proceed?

Barriers and latches, `Promise.all` and `gather` and what they do on failure, the sequential-await trap, and the counterweight: parallelising a call fan-out multiplies load on whatever is downstream. Thundering herds and single-flight coalescing.

Structured Concurrency & Cancellation6

Who owns this task, and what happens when nobody wants the answer?

Child tasks with a clear lifetime, cancellation as a first-class concern rather than an afterthought, propagation to children, timeouts against deadlines, and the orphaned background task nobody is waiting for and nobody stops.

Immutability & Concurrency Control7

Can we make coordination unnecessary instead of correct?

The strategies that reduce synchronization rather than perfecting it: immutability, copying versus sharing, copy-on-write snapshots, and optimistic against pessimistic concurrency control with the contention threshold that decides between them.

Patterns & Anti-Patterns6

What shape does this problem already have a known answer for?

The pattern catalogue with problem, structure, trade-offs and failure modes for each — and the anti-patterns that show up in real code review: one global lock, unbounded spawning, locks held across I/O, swallowed task exceptions, and lock-free code written without a reason.

Parallel Performance8

Why is eight cores not eight times faster?

Where the speedup goes: serial fractions, synchronization, memory bandwidth, cache locality destroyed by tasks bouncing between cores, NUMA, affinity, and the numerical fact that parallel reduction can change floating-point results.

Debugging Concurrency9

The bug disappears when I add a log line. Now what?

Why concurrency bugs resist ordinary debugging, and what works anyway: lock wait metrics, thread and async task dumps, contention profiling, race detectors, deterministic replay, and stress testing designed to shake out schedules that normal runs never produce.

Concurrency in Real Systems8

Which concurrency model should this server use?

Thread-per-request against event-driven against hybrid runtimes, UI thread constraints, how databases solve concurrency for data but not for your application memory, and the boundary where a local mutex stops meaning anything at all.

Concurrency in Agent Systems4

Can these tool calls run at the same time?

Parallel tool execution and what it costs in load, money and determinism; agents racing on the same document; and cancelling a long-running agent run without leaving tool calls, queue entries and side effects behind.

What this domain is not

It is not a list of thread APIs, and it does not re-teach the mechanisms.

Operating Systems teaches you what a mutex is. This domain tells you which region to put it around, what happens in the schedules where you got that wrong, and whether you needed one at all. Where a lesson touches a mechanism — a thread, a semaphore, a context switch, an event loop — it links the Operating Systems lesson and moves straight on to the reasoning. Nothing here asks you to memorize an API surface; every lesson asks what invariant is being protected, which interleavings exist, what the synchronization actually guarantees, and what the concurrency cost.

Concurrency is not parallelism

Concurrency is overlapping progress — a structure in which several pieces of work are all underway. Parallelism is simultaneous execution — more than one thing running at the same instant on different hardware. A system can be concurrent without being parallel, parallel without being concurrent, both, or neither. Almost every confused conversation about performance starts here.

A race condition is not a data race

A race condition is a logical bug: correctness depends on timing, and some schedule produces a wrong answer. A data race is a memory-model term: unsynchronized conflicting access to the same location, at least one of them a write. C++ makes a data race undefined behaviour; JavaScript and Python do not have the same rule. You can have a race condition with no data race anywhere — that is the common case in production.

A task is not a thread

A runtime may schedule thousands of tasks over a handful of threads, or one task per thread, or move a task between threads mid-flight. "Ten thousand concurrent requests" says nothing about how many threads exist. Ask what the unit is, and who schedules it.

A language memory model is not a CPU memory model

The guarantees you program against come from the language: what is atomic, what establishes happens-before, what the compiler may reorder. Underneath, the processor has its own ordering rules. They are related, they are not the same, and reasoning at the wrong level is how "but I wrote it in that order" bugs get shipped.

Nothing is recommended without its cost

Every lesson carries required complexity and alternatives fields. A lesson that cannot name the simpler thing to try first is teaching a default rather than a decision — and concurrency is always bought with complexity, so the price goes on the label.

A simulated schedule is not a measurement

Every schedule, timeline and speedup curve on this site is produced by a model here and is labelled as such. There is no universal ideal thread count, and lock-free is a progress guarantee, not a performance promise.