5 ms·
The author appears to have reinvented Communicating Sequential Processes (CSP). http://www.usingcsp.com/cspbook.pdf http://www.usingcsp.com/cspbook.pdf The (s
by erpellan 8y ago
The author appears to have reinvented Communicating Sequential Processes (CSP).
http://www.usingcsp.com/cspbook.pdf http://www.usingcsp.com/cspbook.pdf
The (simplified, and as I understand it) gist of concurrency in CSP is that the program is expressed as a series of parallel (PAR) and sequential (SEQ) operations.
Everything in a PAR block will run in parallel and all their outputs will be collected and fed as the input to the next SEQ. Everything in a SEQ will run sequentially as a pipeline until the next PAR. Every PAR must follow a SEQ and vice versa, as two PARS or SEQS next to each other will simply coalesce.
eg.
PAR
longCall1
longCall2
longCall3
SEQ
reduceAllThreeResults
doSomethingWithTheReducedResult
PAR
nextParallelOp1
nextParallelOp2
etc.
- jimmoores 8y agoThis is realised in a real language as occam. I've never understood why so few languages have a par construct, it's much more natural than asynchronous launching.
- lou1306 8y agoThe neat thing is that PAR and SEQ do not compose mere operations; they compose other CSP processes. This gives CSP a very regular, self-similar structure. (The "basic" processes are just the send/receive of a value over a channel. By the way, Go channels are a direct lift from CSP!)
- m0meni 8y agoThis misses the point of the article. It's short-sighted to say that he's reinvented CSP given that the entire concurrency model in Go is based around CSP, and the author is already aware of it. The article is more related to RAII, scope, lifetimes, etc. than any model of concurrency.
- mpweiher 8y agoChannels are lifted from CSP, but PAR is obviously missing.
- zbobet2012 8y agopar is "select" effectively. While that isn't 100% the case, it is true.
- mpweiher 8y agoHuh? I thought "select" was "ALT"??
- kolpa 8y ago'go' is PAR with different syntax (Everything after the 'go' line is implicitly one branch of the PAR) 'select' is ALT
- zbobet2012 8y agoThat's correct apologies.
- mpweiher 8y agoHmmm...as far as I understood the FA, the point is exactly that 'go' is unlike PAR in important respects. 'go' is more like a goto, the new goroutine is spawned, without any scoping. PAR opens a scope where all the contained routines are executed in parallel, but all of these must have terminated before the statement after the PAR is executed. ?
- pdonis 8y ago> Everything after the 'go' line is implicitly one branch of the PAR No, it isn't, because Go doesn't do the italicized part: "Everything in a PAR block will run in parallel and all their outputs will be collected and fed as the input to the next SEQ."
- kolpa 8y agogoroutines are CSP: https://golang.org/doc/faq#csp https://golang.org/doc/faq#csp The FAQ even mentions Occam, mentioned by another commenter: "Occam and Erlang are two well known languages that stem from CSP. Go's concurrency primitives derive from a different part of the family tree whose main contribution is the powerful notion of channels as first class objects."
- jimmoores 8y agoYes, the communications primitives line up with event synchronizations and the select with the external choice operator, but Go doesn't implement the process operators parallel, seq and interleaved. This is what the guy is getting at, without realizing it. The slightly grandiose noise in the writing kind of reminds me of Wolfram actually (ouch).
- acjohnson55 8y agoIt's not immediately clear whether or not the reified nursery object breaks this correspondance.
- benjohnbarnes 8y agoI think it does, which seem to make it quite interesting.
- hevrard 8y agoSpeaking of CSP, more broadly process algebras (a.k.a. process calculus) generally have such a "parallel composition" operator. Also, CSP genuine inter-process communication primitive is a _multi-way_ rendezvous which can synchronise an arbitrary number of process, possibly more than two. This is called "interactions" in chapter 2 of Tony Hoare CSP book [1], and channels are built on top of these interactions in chapter 4. This multi-way synchronization is also present e.g. in the LOTOS specification language, which is an ISO standard. The CADP [2] verification toolbox offers various tools like model-checker to verify LOTOS programs, and also to generate executables. For those who know how special/weird the LOTOS syntax is, the CADP folks also develops the LNT language which looks much more like Ada/Pascal. [1] http://usingcsp.com/cspbook.pdf http://usingcsp.com/cspbook.pdf [2] http://cadp.inria.fr/ http://cadp.inria.fr/