Download presentation
Presentation is loading. Please wait.
Published byAthena Whitworth Modified over 9 years ago
1
Structured Thread Models Kahn Process Networks, CSP, Go 1Dennis Kafura – CS5204 – Operating Systems
2
Structured Threads Dennis Kafura – CS5204 – Operating Systems Kahn Process Network Deterministic Processes Unbounded FIFO channels Non-blocking writes, blocking reads 2 Note: figure from Wikipedia
3
Structured Threads CS 5204 – Operating Systems3 Communicating Sequential Processes (CSP) single thread of control autonomous encapsulated named static synchronous reliable unidirectional pointtopoint fixed topology sequential process communication channel
4
Structured Threads Go Language 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(chan int) // unbuffered channel of integers cj := make(chan int, 0) // unbuffered channel of integers Ck := make (chan int, 100) //buffered channel of integers Dennis Kafura – CS5204 – Operating Systems4 See: http://golang.org/doc/effective_go.html#concurrency
5
Structured Threads Go example Dennis Kafura – CS5204 – Operating Systems5 var sem = make(chan int, MaxOutstanding) func handle(r *Request) { sem <- 1 // Wait for active queue to drain. process(r) // May take a long time. <-sem // Done; enable next request to run. } func Serve(queue chan *Request) { for { req <-queue go handle(req) // Don't wait for handle to finish. }
6
Structured Threads 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 Systems6
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.