2 ms·
CSP 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 =
by Jtsummers 3y ago
CSP 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.