1) With Hoare-style condition variables, a signaling thread immediately blocks and does not resume until the signaled thread blocks or leaves the monitor, whereas with Mesa-style condition variables, the signaled thread is placed on the running queue (allowing the signaling thread to first leave the monitor or block) or waits for another condition. Although Hoare-style variables provide for simpler proof rules, Mesa-style variables are usually used in real operating systems. 4) int xmit, rcv; monitor Radar { int state; condvar r; void transmit() { while(state == 1) r.wait(); } void receive() { while(state == 0) r.wait(); } void release() { state = (state + 1) % 2; r.signal(); } void init() { state = 0; } } void transmitter() { while(1) { Radar.transmit(); // Transmit Radar.release(); } } void receiver() { while(1) { Radar.receive(); // Receive Radar.release(); } } void main() { xmit = thread_create(transmitter); rcv = thread_create(receiver); Radar.initRadar(); thread_start(xmit); thread_start(rcv); } 5) monitor BouncerRobot { int num_old, num_young, num_drinkers, num_smokers; condvar young, middle, old; int EnterRestaurant(int age, boolean wantToDrink, bool wantToSmoke) { if(age < 40) { while(num_drinkers > 0 || (wantToSmoke && num_old > 0)) young.wait(); if(wantToSmoke) num_smokers++; num_young++; } else if(age > 90) { while(num_smokers > 0 || (wantToDrink && num_young > 0)) old.wait(); if(wantToDrink) num_drinkers++; num_old++; } else { while((wantToSmoke && num_old > 0) || (wantToDrink && num_young > 0)) middle.wait(); if(wantToSmoke) num_smokers++; if(wantToDrink) num_drinkers++; } } int ExitRestaurant(int age, boolean wasADrinker, boolean wasASmoker) { if(age < 40) if(--num_young == 0) { middle.broadcast(); old.broadcast(); } if(age > 90) if(--num_old == 0) { middle.broadcast(); young.broadcast(); } if(wasASmoker) { if(--num_smokers == 0) old.broadcast(); } if(wasADrinker) { if(--num_drinkers == 0) young.broadcast(); } }