Nice write up. The logic of the sleep and wakeup code, which explicitly pass control from writer to reader and back again, clearly shows how pipes lead to the more refined Communicating Sequential Processes (CSP) concept.
It has some unusual notation you might need to get used to, but it's a real goldmine of ideas.