====== Week 9 ====== ~~NOTOC~~ ===== Monitors (cont'd) ===== **Assignment 4: Dining Java Philosophers** * Assigned: Mon, Oct 19 * Due: Fri, Oct 30 * {{ diningjavaphils.pdf |PDF}} * Questions? **Notes** * Ben-Ari slides: {{slides.pdf|PDF}} * My monitor notes: {{:courses:cs377-201603:cs377-monitors.pdf|PDF}} * Monitor state transition diagram: {{monitor-state-diagram.pdf |PDF}} \\ \\ **Class participation with monitors:** * The One-Lane Bridge problem: Cars coming from the north and south arrive at a one-lane bridge. Cars heading in the same direction can cross the bridge at the same time, but cars heading in opposite directions cannot. * can we find a way to be safe, fair, and efficient? * handout: {{onelanebridgemonitor-1up.pdf |PDF}} (with thanks to Charlie Hughes!) ===== Channels, CSP, and Go ===== * CSP and Go! * Hoare's 1978 CSP paper: https://spinroot.com/courses/summer/Papers/hoare_1978.pdf * Go implementation of examples from paper: https://godoc.org/github.com/thomas11/csp * Rob Pike's Google I/O 2012 - Go Concurrency Patterns: https://youtu.be/f6kdp27TYZs * Peter Welch's slides introducing CSP and occam-pi (but we will use Go this semester!) * [[courses:cs377-202001:welch-lectures:top|Occam-pi Lecture Notes]] * even though we won't be programming in occam-pi, I want to give you a flavor of it * because: * ultimate lightweight processes! * composition! * **//Objects Considered Harmful//** (slide 27 of [[https://www.cs.vassar.edu/_media/courses/cs377-202001/welch-lectures/motivation.pdf|motivation.pdf]] slides) * **//Legoland://** (slide 83-end of [[https://www.cs.vassar.edu/_media/courses/cs377-202001/welch-lectures/basics.pdf|basics.pdf]]) \\ \\ * Demo and codewalk of [[csp-dining-phils|csp-dining-philosophers.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) \\ \\