Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monitors. Controls Condition variables –Value –Queue –ONLY used in a monitor Signal "promotes" or "de-queues" a waiter Two types –Signal & exit(C.A.R.

Similar presentations


Presentation on theme: "Monitors. Controls Condition variables –Value –Queue –ONLY used in a monitor Signal "promotes" or "de-queues" a waiter Two types –Signal & exit(C.A.R."— Presentation transcript:

1 Monitors

2 Controls Condition variables –Value –Queue –ONLY used in a monitor Signal "promotes" or "de-queues" a waiter Two types –Signal & exit(C.A.R. Hoare) –Signal & continue (Per Brinch Hansen- Mesa)

3 Signal & Continue Waiting thread still waits for actual exit Allows system to 'prepare' the waiter Used in Java

4 Inside the Monitor May want to wait for something Condition variable controls the wait While condwait thread is moved outside the monitor

5 Sample – acts like a semaphore boolean busy = false; Conditionavail; MonitorEntry void getRes() // same as "P" {if (busy) wait(avail); // put me in queue busy=true;// now held } MonitorEntry void freeRes() // same as "V" {busy=false; signal (avail); signal (avail);}

6 Readers & Writers Condition canwrite, canread; boolean writelock=false; int rdrs=0; monitorEntry void beginread() {if (writelock || queue(canwrite)) wait canread; ++rdrs; signal (canread); } MonitorEntry void endread() {--rdrs; if (rdrs==0) signal(canwrite); } monitorEntry void beginWrite() {if (rdrs>0 || writelock) wait (canwrite); writelock=true;} monitorEntry void endwrite() {writelock=false; if (queue(canread)) signal(canread); else signal(canwrite); }


Download ppt "Monitors. Controls Condition variables –Value –Queue –ONLY used in a monitor Signal "promotes" or "de-queues" a waiter Two types –Signal & exit(C.A.R."

Similar presentations


Ads by Google