Monitors
Home ] Up ] A Steam Boiler ] Race Conditions ] [ Monitors ] Synchronization ] A Fixed Steam Boiler ] Deadlock ] Starvation & Livelock ]

 

 

The concept of a monitor was pioneered in the 1970s by C.A.R. Hoare and Per Brinch Hansen

A monitor applies the principle of mutual exclusion to a set of procedures. When mutual exclusion occurs, only a single thread can have access to a shared resource at a time. Other threads that attempt to access the shared resource are forced to wait until the thread that is accessing the resource has done with it..

In order for a thread to gain the necessary access to a shared resource, it must acquire a lock and hold it until the thread has completed the necessary actions on that resource. Then it must release the lock, so that any waiting threads may compete to acquire the lock. Only one of the threads will win, and the rest continue to wait.

This mechanism assures that access to the shared resource is serialized, so that only one thread may access the resource at a time.

In general, it is good practice to minimize the amount of time that a thread can hold a lock. If a thread holds a lock too long, it can negatively impact the performance of the system.

Note: Per Brinch Hansen, one of the pioneers of monitors was not pleased at what he saw in how Java implemented the idea of a monitor.  See http://brinch-hansen.net/papers/1999b.pdf for more details.

 

The page was last updated February 19, 2008