1 / 6

Monitors

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. Hoare) Signal & continue (Per Brinch Hansen-Mesa). Signal & Continue. Waiting thread still waits for actual exit

effie
Download Presentation

Monitors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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; Condition avail; 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); }

  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); }

More Related