Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · How Computers Work · Many programs, one machine · about 21 min to read

Play it as a journeyTutor comes with a plan

Concurrency & the Hardware

Concurrency and the Hardware
Concurrency and the Hardware · Open board

Two cores reaching for the same shared counter at once, and the three fixes for it: a lock, an atomic add, and giving each core its own copy.

Before you start. Processes, Threads & the Kernel gave you a thread, one flow of instructions moving through a program, and a process, the box that can hold several threads sharing the same memory. This lesson is about what happens the instant two of those threads reach into that shared memory at once, using the CPU’s one-instruction-at-a-time steps from The CPU (fetch-decode-execute, the ISA, assembly).

Lesson 10 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 21 March 1986: a keystroke, and a beam with no target
  • A kitchen with one cook, then two: concurrency and parallelism
  • One pencil at a time: the lock, and its bill
  • A pencil stroke nothing can interrupt: the atomic fix
  • Ten helpers, one step nobody can split
  • Measured on this machine
  • Deadlock, and its cousins
  • Cache coherence and false sharing
  • Four ways to survive sharing
  • Amdahl’s Law, worked and measured

Terms it explains: race condition, concurrent, parallelism, lock, atomic, lost update, Compare-and-swap (CAS), lock-free, deadlock, 2PL, SSI, Cache-coherence, false sharing, happens-before, linearizability, Threads and locks, Actors, async / event loop, CSP / channels, actor / message passing, Amdahl's law, cache coherence (MESI), CAS, concurrency, coroutine/channel, critical section, memory barrier/fence, memory reordering, mutex/lock, mutual exclusion, starvation / livelock.

Lab

Ninety-five percent of the job splits across cores. How much faster can it possibly finish?

Leave The part that can be split up at 95%, drag Cores you throw at it upward, and watch What the next core buys.

Open The parallel ceiling

Thirty-two hands share one key. The room is no slower than with two, so where did the extra hands go?

Stay on One key for the whole room, drag Hands that need the key from 2 to 32, and watch Time spent waiting.

Open The one key

Related papers

Review How Computers Work