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 07 · How Computers Work · Build it concurrent · with code: Go · about 18 min to read

Play it as a journeyTutor comes with a plan

One key, many hands

Concurrency and the Hardware
Concurrency and the Hardware · Open board

Two cores reaching for one shared counter, with a lock, an atomic add and a private copy as the ways to stop them clobbering each other. This lesson asks what those fixes cost once many threads, not two, are in the queue.

Before you start. A thread is one line of work inside a program, and a core is one of the chip’s processors, able to run one thread at a time. A lock lets one thread at a time touch a shared value, and every other thread that wants it has to wait (Concurrency & the Hardware). The scheduler, the part of the kernel that hands out turns on the cores, sets a waiting thread aside until it is woken (Waiting without spinning). Correct is the easy half. This lesson is about fast.

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

  • 9 June 1996: Linux gets a second processor, and one key
  • One key to the stockroom: the critical section
  • The line at the door: contention
  • Way one: spend less time inside the critical section
  • Way two: many stockrooms, lock striping
  • Way three: no room at all, and the cache line that still bills you
  • When most visitors only look: the read-write lock

Terms it explains: critical section, 96.4 percent, contention, 979,480, lock striping, cache line, 20 milliseconds, read-write lock, actor / message passing, Amdahl's law, async / event loop, atomic, cache coherence (MESI), CAS, concurrency, coroutine/channel, 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