This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CMPSCI 377 Operating Systems Spring 2010 Lecture 9: February 18 Lecturer: Prashant Shenoy TA: Vimal Mathew & Tim Wood 9.1 Monitors While semaphores can be a powerful synchronization mechanism, they have some drawbacks which make them difficult to use in practice. Semaphores are a low level mechanism, and improperly placed signal and wait calls can lead to incorrect behavior. Additionally, semaphores are a global data structure which are not explicitly tied to a critical sectionthey can be called from any thread at any point in the program. These characteristics can cause semaphores to be difficult to use, and improper usage can easily lead to bugs. A monitor is a higher level synchronization mechanism that tries to resolve some of these issues. A monitor can be viewed as a class that encapsulates a set of shared data as well as the operations on that data (e.g. the critical sections). The monitor is implemented in such a way so as to guarantee mutual exclusiononly one thread calling a method in the monitor class can run at a time. We consider a thread to be in a monitor if it has acquired control of the monitor; the monitor automatically ensures that only one thread can be in the monitor at a time. A monitor contains a lock and a set of condition variables . The lock is used to enforce mutual exclusion. The condition variables are used as wait queues so that other threads can sleep while the lock is held. Thus condition variables make it so that if a thread can safely go to sleep and be guaranteed that when they wake up they will have control of the lock again. In Java, monitors can be used by adding the synchronized keyword to a method declaration. This will make it so that only one thread can execute the method at a time. This eliminates the need to manually acquire and release locks or call semaphore operationsthe mutual exclusion is provided through the monitor system....
View Full Document
This note was uploaded on 09/30/2010 for the course CS 377 taught by Professor Corner during the Fall '08 term at UMass (Amherst).
- Fall '08
- Operating Systems