The library

How a program runs

Reason about concurrent code from the memory model rather than from intuition, well enough to say why a program that looks correct is not, to choose the cheapest construct that is still correct, and to recognise the bugs that only appear under load

What Two Threads Can Break

Concurrency goes wrong in ways that reading the code does not reveal, because the code you wrote is not the order that runs. This course derives the hazards, the guarantees that remove them, and what each guarantee costs.

8 lessons, written and corrected before you arrived. Reading them here needs no account. The first reads the whole way through; the others open and then stop, because a page nobody owns cannot tell who is reading it. Starting the course gives you your own copy, where every idea has problems standing under it and you can ask about any sentence.

Start reading

  1. 01Two Threads, Four Steps, and Six Different Programs You Did Not WriteThe code you read is one order. The machine may run any order that keeps each thread internally in sequence. Write them all out once and the whole subject becomes concrete.
  2. 02The Statement You Wrote Is Three Instructions and the Danger Lives Between Themopening onlyAn increment reads, adds and writes. The scheduler may switch between any two of those. This lesson locates the gap exactly and says which operations have no gap at all.
  3. 03A Perfectly Correct Lock Around Exactly the Wrong Piece of Codeopening onlyA lock lets one thread at a time into a region. Choosing the region is the whole skill, and the usual mistake is a flawless lock that leaves the broken state visible anyway.
  4. 04Four Things Must All Be True, So Breaking Any One of Them Is Enoughopening onlyDeadlock needs four conditions at once. That is good news, because it means there are four places to attack it, and in practice one of them wins almost every time.
  5. 05The Loop Is Still Spinning and the Flag Was Set Ten Minutes Agoopening onlyA write can simply never reach another thread. No reordering is involved and no lock would help. This is a separate hazard with a separate cause and a separate fix.
  6. 06One Relation Settles Every Argument About What a Thread Is Allowed to Seeopening onlyHappens-before is the whole guarantee. If a chain of edges runs from a write to a read, the read sees it. If no chain does, nothing is promised at all.
  7. 07Write It Only If Nobody Moved It, and Try Again If They Didopening onlyOne instruction compares and writes in a single step and tells you whether it worked. Built into a retry loop it removes blocking, and puts a different failure in its place.
  8. 08Seven Lessons of Difficulty That All Disappear If Nobody Shares Anythingopening onlyEvery problem in this course needed two threads touching one piece of state. Remove the sharing and the problems do not get easier, they stop existing. Here is the price.