Book 1: Take Turns
Start with two jobs that need to share a thread. You’ll make them take turns, give each one a way to remember its progress, and build the scheduler that runs them.
A hands-on series for systems programmers
Understand async and coroutines inside out.
Build it one working piece at a time. Runnable examples, exercises, and language notes help you follow along from Go, Rust, Zig, Odin, or C.
Three books in development · By Peter Mbanugo
Waiting for the simulated oven.
Next step: shelve the bread.
This stays in the task’s state.
Gives another ready task a turn.
The same thread takes an order.
Start with something familiar
The program has bread to bake and orders to take. Waiting for the oven doesn’t have to hold up the orders. The question is how the program lets go of one task to continue with another, and knows when and where to continue with the former.
The bread task puts a loaf in the oven. It keeps “shelve the bread” in its state and returns a wait request.
The scheduler takes back control. The same thread can now run the order task while the baking works on its non-blocking task.
When the non-blocking baking ends, the bread task becomes ready. On its next turn, it reads its state and shelves the loaf.
Close to stop. Open again to replay.A still view of the handoff.
This is a program with a simulated clock. The oven models waiting; the thread runs one task step at a time.
A little look inside
The bakery, the saved state, and the same jobs inside a program.
You write async code. But when a task pauses, what lets it carry on later? I’m writing One Thread, Many Tasks to make those steps visible.
Picture one baker. Bread in the oven. A customer ready to place an order. The bread needs more time. The baker can take the order. The next step for the bread is simple: take it out, and put it on the shelf.
Now put those jobs in a program. We’ll model them on one thread, with a simulated clock. Here, a task does one piece of work, then returns. Its progress lives in a struct, so the next call can pick up where it left off.
The animation shows the bread task keeping its phase after a call returns. These two lines save the next step, then ask to wait: b.phase = .Shelve and return coop.sleep_for(BAKE_TICKS). The bake duration is four simulated ticks.
Control returns to the scheduler. The order task can run. When the timer is up, the bread task becomes ready. On its next turn, it continues at the saved step. The execution marker moves between calls while task data stays in place. At tick nine, the bread task shelves the loaf.
Across three books, you’ll build this runtime yourself, in Odin. First, make tasks take turns. Then add waiting and channels. Then coordinate the work, and bring it to a clean stop. You’ll predict what happens, run the code, and check the trace.
The film closes with an invitation to follow the books as I write and receive previews and launch news at learnconcurrency.dev.
One Thread, Many Tasks
You’ll work on the same runtime through all three books. Each book picks up where the previous one left off. You keep the code you’ve written and add what the next program needs.
Start with two jobs that need to share a thread. You’ll make them take turns, give each one a way to remember its progress, and build the scheduler that runs them.
You’ll give tasks a way to wait and wake up while other work carries on. You will add timers, events, and channels, and see how a full queue can make a sender wait.
You’ll bring the pieces together in larger programs, with futures, actors, and pipelines. The runtime becomes more capable to manage tasks lifetime, cancellation, and how to shut down cleanly.
Work through it yourself
Each chapter gives you a small program to run and change. Before running it, you’ll work out which task will run next and what happens when another task has to wait.
Then you’ll run it and look at the log of what each task did. After that you'll compare the result with your prediction. If something surprises you, you can follow it back to the code.
The exercises ask you to add, change, or fix something. You’ll write tests to check that the program behaves as you intended.
The examples use Odin, with language notes and appendices for Go, Rust, Zig, and C readers. Familiarity with systems programming helps. You can start without knowing concurrency because the programs use one thread and simulated time so you can follow what happens.
Follow two tasks through the program.
Tick 5
Tick 6
Tick 9
Follow the work as it takes shape
Selected draft chapters and exercises to try. Get News when the books are ready.