Structured Thread Models Kahn Process Networks CSP Go

  • Slides: 6
Download presentation
Structured Thread Models Kahn Process Networks, CSP, Go Dennis Kafura – CS 5204 –

Structured Thread Models Kahn Process Networks, CSP, Go Dennis Kafura – CS 5204 – Operating Systems 1

Kahn Process Network n n n Structured Threads Deterministic Processes Unbounded FIFO channels Non

Kahn Process Network n n n Structured Threads Deterministic Processes Unbounded FIFO channels Non blocking writes, blocking reads Note: figure from Wikipedia Dennis Kafura – CS 5204 – Operating Systems 2

Structured Threads Communicating Sequential Processes (CSP) sequential process n n n single thread of

Structured Threads Communicating Sequential Processes (CSP) sequential process n n n single thread of control autonomous encapsulated named static communication channel n n n CS 5204 – Operating Systems synchronous reliable unidirectional point to point fixed topology 3

Structured Threads Go Language n go routine Executed concurrently ¨ No return value ¨

Structured Threads Go Language n go routine Executed concurrently ¨ No return value ¨ Syntax: go list. sort() ¨ n Channels Typed ¨ Specified bounds on channel capacity ¨ Used for ¨ n n ¨ Return value(s) from go routine Communication with/among go routine(s) Syntax n n n ci : = make(chan int) // unbuffered channel of integers cj : = make(chan int, 0) // unbuffered channel of integers Ck : = make (chan int, 100) //buffered channel of integers See: http: //golang. org/doc/effective_go. html#concurrency Dennis Kafura – CS 5204 – Operating Systems 4

Structured Threads Go example var sem = make(chan int, Max. Outstanding) func handle(r {

Structured Threads Go example var sem = make(chan int, Max. Outstanding) func handle(r { sem <- 1 process(r) <-sem } *Request) // Wait for active queue to drain. // May take a long time. // Done; enable next request to run. func Serve(queue chan *Request) { for { req <-queue go handle(req) // Don't wait for handle to finish. } } Dennis Kafura – CS 5204 – Operating Systems 5

Structured Threads Common Ideas n Concurrency Single threaded, deterministic processes ¨ Non-determinism limited to

Structured Threads Common Ideas n Concurrency Single threaded, deterministic processes ¨ Non-determinism limited to interleaved execution of deterministic processes ¨ n Interaction Communication only via specified channels ¨ no shared memory ¨ n 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 – CS 5204 – Operating Systems 6