====== Week 7 ====== ~~NOTOC~~ ===== From Semaphores to Monitors ===== **Monitors** * Marc's Lecture Notes: {{ cs377-monitors.pdf |PDF}} * Ben-Ari Ch 7 * begin slide 146 * Dr. Seuss on Deadlock: * [[zax|The Zax]] * Semaphores vs. Monitors ^ Semaphore ^ Monitor ^ | ''wait'' may or may not block | ''waitC'' always blocks | | ''signal'' always has an effect | ''signalC'' has no effect \\ if queue is empty | | ''signal'' unblocks an arbitrary blocked process | ''signalC'' unblocks the process at the head of the queue | | a process unblocked by signal can resume execution immediately | a process unblocked by signalC must wait for the signaling process to leave monitor | * 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? * {{onelanebridgemonitor2026.pdf|PDF}} (with thanks to Charlie Hughes!) ===== Monitors in Java ===== * Java case study (starter code for Assign 4) * starter code for Assign 4 (for //**after**// the break) * this version deadlocks! * you will use two different approaches to fix: * synchronized methods * synchronized code blocks \\ \\ ===== Midterm Programming Assignment ===== * Dining UPC Philosophers {{diningupcphils.pdf |PDF}} * **Note:** version 3 is required (sorry for any confusion!) * it can definitely be implemented with busy waiting * the //challenge// is whether it can be implemented without busy waiting! * Assigned: Thu, Feb 19 * Due: Tue, Mar 3, 11:59pm (Tue before Spring break)