ContentsThe library

Doing Two Things at Once

A Door That Admits One

Last timeTwo Things, One Piece of State

The standard remedy is to mark a region of work and allow only one worker inside it at a time. That buys correctness, and it buys it by making every other worker wait.

The fix for the previous lesson is blunt and it works. Mark the region of work

that touches the shared state. Allow one worker inside at a time. Everybody else

waits at the door.

That is the whole idea, and almost everything difficult about concurrency is a

consequence of the waiting rather than of the idea.

It guards a region, not a variable

The common mental picture is of a lock attached to a piece of data, as though the

data were now safe. It is not. A lock is a convention, and the convention

protects a stretch of work.

FIG 1The three parts of any guarded region
The region is defined by agreement rather than by the machine. Nothing stops a path from reaching the shared state without entering, which is why partial coverage is the most common way an apparently locked system is still wrong.

The practical test is simple. List every path that reads or writes the shared

state. If any of them does not pass through the same door, the arrangement buys

you the waiting without the safety.

The lesson stops here

8 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Update That Vanished
  2. 02A Door That Admits Oneyou are here
  3. 03The Bill Arrives as Latencyopening only
  4. 04Everybody Holding, Nobody Movingopening only
  5. 05Try, Check, Try Againopening only
  6. 06The Promise Is Weaker Than You Thinkopening only
  7. 07The Ceiling You Cannot Buyopening only
  8. 08The Problem You Decide Not to Haveopening only

Read alongside