The chapter closes with a small, real coordination - two consumers waiting on the same slot, and a producer feeding them one value at a time. It shows FIFO wake order carrying distinct payloads - the first waiter gets the first value.
Run two blocked consumers and a producer that delivers two values, one per wake, in order.
This is the chapter’s payoff: a tiny rendezvous where several green threads line up for a resource and are served fairly, one at a time. The FIFO wait queue guarantees consumer 1 (which blocked first) is woken first and so takes the first value; consumer 2 takes the second. Distinct waiters, distinct payloads, deterministic order.
The producer’s yield between deliveries is the subtle, important part. If it
delivered both values back to back, it would overwrite the slot before consumer 1 ever
read it. By yielding right after the first wake, the producer steps aside and lets the
just-woken consumer run and consume 10, and only then produces 20 for consumer 2.
That deliberate handoff - produce, wake, step aside - is exactly the discipline a
correct channel needs, which is where the next chapters go, once you can also make a
task wait for time to pass.
// producer step (state machine): deliver 10, Wake, yield;// on resume: deliver 20, Wake, Done.// Yielding after the first Wake lets consumer 1 read 10 before// consumer 2's value overwrites the slot - handoff, not a race.// spawn order: consumer, consumer, producer