3 ms·
CSP doesn’t have queues, only blocking channels. Some implementations may provide them on top, as go does. I would suggest reviewing the Hoare book on CSP, it’
by fidotron 3y ago
CSP doesn’t have queues, only blocking channels. Some implementations may provide them on top, as go does.
I would suggest reviewing the Hoare book on CSP, it’s very readable.
- dekhn 3y agoI have read it (along with lots Russ Cox wrote about CSP and Go, such as https://swtch.com/~rsc/thread/ https://swtch.com/~rsc/thread/) and McIlroy (https://www.cs.dartmouth.edu/~doug/sieve/sieve.pdf https://www.cs.dartmouth.edu/~doug/sieve/sieve.pdf) . From what I can tell, CSP channels are semantically equivalent to a particular subtype of queues and use the same OS primitives. I'm not an OS expert but I've worked with distributed systems and threads for decades, and nobody I've asked has disagreed that Go's implementation of CSP is an M:N thread model with (blocking) queues.
- deleted 3y ago[deleted]
- Jtsummers 3y agoCSP doesn't need queues (buffered channels) as a primitive because you can create them. Here's a Queue in CSP from the CSP book I linked elsewhere: BUFFER = P⟨⟩ where P⟨⟩ = left?x → P⟨x⟩ P⟨x⟩⌢s = (left?y → P⟨x⟩⌢s⌢⟨y⟩ | right!x → Ps ) If data can be read from left it is and it's enqueued, if data can be written to right (because a reader is available) it dequeues it. But neither the read nor the write block the entire process. Go's buffered channels act in the same way so end up offering a shortcut versus pure CSP. There are other ways that Go deviates from CSP (shared memory, among others) but with channels it's not deviating, just optimizing an existing behavior.