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 04 · How Computers Work · Inside the operating system · with code: Go · about 20 min to read

Play it as a journeyTutor comes with a plan

Waiting without spinning

Concurrency and the Hardware
Concurrency and the Hardware · Open board

Two cores reaching for one shared counter, and a lock that lets only one of them touch it at a time. This lesson is about what comes after the lock: a thread that holds it, finds nothing it can do yet, and has to wait.

Before you start. When two threads touch the same memory at once, an update can be lost, and a lock fixes that by letting only one thread at a time near the shared value (Concurrency & the Hardware). The scheduler, the part of the kernel that hands out turns on the cores, can set a waiting thread aside and give its turns to others until something wakes it (Whose turn, and who decides).

Lesson 22 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

  • Palo Alto, 1977: “an easy one”
  • A lock keeps the cooks apart. It doesn’t say when: the bounded buffer
  • Staring at the shelf: busy-waiting
  • Sit down, and wait for the bell: the condition variable
  • The bell nobody heard: the lost wakeup
  • Why look twice: the Mesa rule
  • Counting permits: the semaphore

Terms it explains: bounded buffer, busy-waiting, condition variable, lost wakeup, semaphore, actor / message passing, Amdahl's law, async / event loop, atomic, cache coherence (MESI), CAS, concurrency, coroutine/channel, critical section, deadlock, happens-before, memory barrier/fence, memory reordering, mutex/lock, mutual exclusion, parallelism, race condition, 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