ContentsThe library

Doing Two Things at Once

Try, Check, Try Again

Last timeFour Things Waiting in a Circle

Instead of a door that admits one, the machine offers an indivisible change-if-unchanged operation. Build on it and nobody waits, but somebody has to repeat their work.

The lock in the earlier lessons solves the problem by making everybody take

turns, and the bill arrives as waiting. There is another approach entirely, and

it rests on one operation the processor gives you.

The primitive

The machine offers an operation that does three things indivisibly: compare a

memory location against a value you expected, and if they are equal, write a new

value, and tell you whether it did. Nothing can occur between the comparison and

the write.

That is enough. If you read a value, compute what it should become, and then

attempt this operation with your old reading as the expectation, you commit your

change only if nothing happened in between. If something did happen, the

operation refuses and tells you so.

FIG 1The shape of every optimistic update
Compare this with the diagram of a guarded region. There is no entry, no exit and no waiting, and the loop back to the top is the price. A worker here is never idle and is sometimes doing work that will be thrown away.

Nobody waits, somebody repeats

The appeal is obvious. A worker that loses the race does not sleep, is not woken,

and does not depend on another worker being scheduled. If a holder of a lock is

suspended by the operating system at the worst moment, everybody behind it waits

for it to be scheduled again. Here there is no holder, so that cannot happen.

The lesson stops here

6 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 Oneopening only
  3. 03The Bill Arrives as Latencyopening only
  4. 04Everybody Holding, Nobody Movingopening only
  5. 05Try, Check, Try Againyou are here
  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