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.
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 contentsThis 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