60 likes | 306 Views
Structured Thread Models. Kahn Process Networks, CSP, Go. Kahn Process Network. Deterministic Processes Unbounded FIFO channels Non-blocking writes, blocking reads. Note: figure from Wikipedia. sequential process. communication channel. Communicating Sequential Processes (CSP).
E N D
Structured Thread Models Kahn Process Networks, CSP, Go Dennis Kafura – CS5204 – Operating Systems
Kahn Process Network • Deterministic Processes • Unbounded FIFO channels • Non-blocking writes, blocking reads Note: figure from Wikipedia Dennis Kafura – CS5204 – Operating Systems
sequential process communication channel Communicating Sequential Processes (CSP) • single thread of control • autonomous • encapsulated • named • static • synchronous • reliable • unidirectional • pointtopoint • fixed topology CS 5204 – Operating Systems
Go Language See: http://golang.org/doc/effective_go.html#concurrency • go routine • Executed concurrently • No return value • Syntax: go list.sort() • Channels • Typed • Specified bounds on channel capacity • Used for • Return value(s) from go routine • Communication with/among go routine(s) • Syntax • ci := make(chanint) // unbuffered channel of integers • cj := make(chanint, 0) // unbuffered channel of integers • Ck := make (chanint, 100) //buffered channel of integers Dennis Kafura – CS5204 – Operating Systems
Go example varsem = make(chanint, MaxOutstanding) funchandle(r *Request) { sem<- 1 // Wait for active queue to drain. process(r) // May take a long time. <-sem // Done; enable next request to run. } funcServe(queue chan *Request) { for { req<-queue go handle(req) // Don't wait for handle to finish. } } Dennis Kafura – CS5204 – Operating Systems
Common Ideas • Concurrency • Single threaded, deterministic processes • Non-determinism limited to interleaved execution of deterministic processes • Interaction • Communication only via specified channels • no shared memory • Unify communication and synchronization • Reads block when data unavailable • Write blocks if channel capacity exceeded or receiver not ready • Relates state of receiver to state of sender Dennis Kafura – CS5204 – Operating Systems