Memory & Concurrency
Paged memory and a collector for the heap, then threads sharing it: the race, the locks and the deadlock they bring, the event loop that avoids both, and actors that share nothing.
How Computers Work · Software Engineering
Before you start
Some lessons here build on lessons from other arcs: The Stack & The Heap, CPU Caches & Locality, A Tiny CPU, Instruction by Instruction.
- 1
Virtual Memory & Page Tablesin review
Computers · Memory · ~25 minEvery address a program uses is a lie the hardware keeps: a page table maps it to a frame, a tiny buffer remembers the last few answers, and a page not in memory is a fault that reads the disk.
- 2
Garbage Collection: Mark & Sweepin review
Computers · Memory · ~25 minLive means reachable from a root. Mark everything the program can still reach, sweep the heap and free the rest, cycles included, then compact if the holes matter.
- 3
Race Conditionsin review
Software · Concurrency · ~25 minTwo threads each add one to a counter and the result is wrong, because an increment is three instructions and the scheduler may switch between any two. The bug comes and goes with the timing.
- 4
Locks, Deadlock & Dining Philosophersin review
Software · Concurrency · ~25 minA lock fixes the race and opens a new trap: five philosophers each pick up the left fork and wait forever for the right. Deadlock is a cycle of waits, and every cure makes the cycle impossible.
- 5
The Event Loopin review
Software · Concurrency · ~25 minOne thread, no races, and still a timer, a promise, and a file read all in flight: the script runs to its end, microtasks drain, then one task at a time. Order comes from the queues, not the clock.
- 6
The Actor Modelin review
Software · Concurrency · ~25 minAn actor owns its state and handles messages one at a time: nothing shared, so nothing races or locks. Two workers incrementing a counter get six in any order. The price is a moment nobody can see.