Execution models, under the hood
From CPU to Coroutines
From how a computer runs a single line of code, through memory and GC, waiting, processes, context switches, threads, thread pools, event loops and coroutines — one step at a time. Every term is defined before it is used, and each step is motivated by the problem the previous one left behind. The code is language-neutral pseudocode, and every animation is the output of a deterministic simulator. The last two chapters tie it together: sixty years of history explaining why these methods appeared in exactly this order (chapter 15), and the measured numbers that close the argument (chapter 16).
Contents
- 01What a computer is made ofCPU · memory · devices · the OS — "the CPU is always running someone's code"
- 02How a line of code runsFetch–decode–execute · memory and addresses · registers and PC · stack and heap
- 03Stack and heap — what goes whereLocals on the stack, objects on the heap · what dies with the function and what does not
- 04Why memory fills up — and GCAllocation · reachability · mark and sweep · pauses and retention
- 05Processes — the first way to share a CPUProgram vs process · address spaces and isolation · the illusion of time-sharing
- 06When does the CPU rest — interrupts and context switchesKernel mode · saving and restoring context · yielding vs preemption · idle
- 07Discovering the wait — IO idles the CPUHow slow devices are · what blocking means · waiting still costs memory
- 08Threads — born because processes were heavyWhat is shared and what is not · three states · the price of sharing
- 09Concurrency ≠ parallelismTwo different words · CPU-bound vs IO-bound · when threads do not help
- 10Server method ① — the thread poolOne thread per request · why a pool · size and cost
- 11Server method ② — the event loopThe C10K answer · register and return · help from the kernel
- 12Coroutines / async-await — callbacks in sync clothingCallback hell · suspend and resume · same execution as chapter 11
- 13Trap ① — one CPU-bound task freezes the loopA preempting pool vs a non-preempting loop
- 14Trap ② — a blocking call on the loopOne blocking line halts the whole server
- 15How we got here — sixty years of evolutionBatch → processes → threads → C10K → event loops → coroutines → virtual threads
- 16Same work, four methodsMakespan · switches · memory · CPU busy, in numbers