Every race in this part will live in the gap the student spots: the moment between seeing a peach and closing your hand on it.
Why this matters
A queue does not coordinate the grabbing, it abolishes it β one hand at a time is correct because nothing overlaps. Nearly all of Part II tries to keep the overlap and be correct anyway; the one approach that gives it up arrives filed under heresy.The second pillar begins β as these things must β with fruit.
The peach table, three ways: the whole of Part II in fruit
If you remember only three things
-
A peach is consumed and memory is not. Two eaters cannot share one peach, but two threads reading the same location get in nobodyβs way β the trouble starts when one of them writes, so the primitives ahead care what a thread does and not merely where it looks.
-
The operating system appears twice in this story. It must provide the coordination primitives that applications call, and it was itself the first program to need them β the provider and the customer of one abstraction.
-
Nothing in the parable involves a computer. A table, some fruit, and several hands reaching at once β the shape holds wherever independent agents go for the same thing at the same moment, so the answers ahead read alike whether the sharer is a kernel or a web server.
The road through Part II
Threads and their API; then the great primitives β locks, concurrent data structures, condition variables, semaphores; then the bugs that haunt them all (races, deadlock); and a heretical alternative, event-based concurrency. Fast and correct β thatβs the whole game.Check yourself
1.The naive peach protocol β see a peach, then grab it β fails. What exactly goes wrong, and what is the computing translation?
2.The student's fix β form a line β works. Why isn't it the end of the story?
3.Why does concurrency belong in an OS course rather than just an application-programming one?