====== Week 9 ======
~~NOTOC~~
===== Assignment: Dining Java Philosophers =====
* Assign 4
* {{ diningjavaphils.pdf |PDF}}
* due: Tue, Mar 31, 11:59pm \\ \\
===== Channels (cont'd) =====
* CSP, Occam, and Golang!
* Peter Welch's slides introducing CSP and occam-pi (but we will use Go this semester!)
* [[courses:cs377-202651:welch-lectures:top|Occam-pi Lecture Notes]]
* Legoland: slides 83--end of {{courses:cs377-202651:welch-lectures:basics.pdf|basics.pdf}}
* remember:
* //everything// is a process in occam and CSP, and
* processes must be composed (explicitly) in sequence (SEQ) or in parallel (PAR) \\ \\
/************
* Rob Pike's Google I/O 2012 - Go Concurrency Patterns: https://youtu.be/f6kdp27TYZs
*************/
* Go demo and starter code
* copy from Marc's directory into your ''cs377'' course directory:
$ cd ~/cs377
$ cd -r /home/mlsmith/cs377-examples/Go ./
* you should see the following files in your local ''Go'' directory:
$ ls
csp-dining-phils.go deadlock.go sort-pump.go
csp-dining-phils-orig.go sieve.go
$
* Demo and codewalk of ''csp-dining-philosophers.go''
* Based on an implementation found [[https://github.com/thomas11/csp|here]]
* on the example given in section 5.3 of Hoare's [[https://dl.acm.org/doi/pdf/10.1145/359576.359585|1978 CSP paper]]
* and diagrammed more closely to the implementation in the [[https://antares.sip.ucm.es/~luis/doctorado06-07/cspbook.pdf|CSP Book]] on p. 57
* you can copy Marc's Go examples directory into your current directory with this command: $ cp -r /home/mlsmith/cs377-examples/Go ./
* Go language features highlighted:
* channels
* select
* Design basis for solution in Go: go routines (processes)
* room (communicates with philosophers over channels)
* for philosophers to enter/leave -- at most 4 at a time to prevent deadlocking, 5th philosopher blocks
* forks (communicate with philosophers over channels)
* philosophers (communicate with forks over channels)
* To run this program:
$ go run csp-dining-philosophers.go
* Nondeterminism
* still!
* sources?
* Demo and codewalk: Sieve of Eratosthenes (Prime Number Sieve) ''sieve.go''
* Go language features highlighted:
* Only one looping construct in Go: for loop
* all three parts are optional: init statement, conditional expression, post statement
* channel declarations in function headers
* can specify syntactically whether channel is for reading from: <-chan or writing to: chan<-
* To run this program:
$ go run sieve.go
// //
* Assignment 5 posted
* Sort Pump Gophers {{sort-pump.pdf|PDF}}
* see a similar example in occam on slides 13--31 of PHW's replicators lecture notes which can be found [[courses:cs377-202651:welch-lectures:top|here]]
* Due: Thu, April 14th