MONITORS IN OPERATING SYSTEM

Monitors

•A monitor is a collection of procedures, variables, and data structures grouped together.
•Processes can call the monitor procedures but cannot access the internal data structures.
•Only one process at a time may be  active in a monitor.
Active in a monitor means in ready queue or CPU with the program counter somewhere in a monitor method.
•A monitor is a language construct.
Compare this with semaphores, which are usually an OS construct.
•The compiler usually enforces mutual exclusion.
•Condition variables allow for blocking and unblocking.
cv.wait() blocks a process.
The process is said to be waiting for (or waiting on) the condition variable cv.
cv.signal() (also called cv.notify) unblocks a process waiting for the condition variable cv.
When this occurs, we need to still require that only one process is active in the monitor. This can be done in several ways:

  1. on some systems the old process (the one executing the signal) leaves the monitor and the new one enters
  2. on some systems the signal must be the last statement executed inside the monitor.
  3. on some systems the old process will block until the monitor is available again.
  4. on some systems the new process (the one unblocked by the signal) will remain blocked until the monitor is available again.

•If a condition variable is signaled with nobody waiting, the signal is lost.
Compare this with semaphores, in which a signal will allow a process that executes a wait in the future to no block.
•Do  not think of a condition variable as a variable in the traditional sense.
It does not have a value.
Think of it as an object in the OOP sense.
It has two methods, wait and signal that manipulate the calling process.

A monitor has four components:
Initialization, private data, monitors procedures, and monitor entry queue.

The initialization component contains the code that is used exactly once when the monitor is created, the private data section contains all private data, including private procedures that can only be used within the monitor. Thus, these private items are not visible from outside of the monitor.
The monitor procedures are procedures that can be called from outside of the monitor.
The monitor entry queue contains all threads that called monitor procedures but have not been granted permissions.

Diagram:


                                          PRIVATE DATA
                                                |
                                                |
                                                |
  ENTRY QUEUE<--------MONITOR PROCEDURES
                                                |
                                                |
                                         MONITOR PROCEDURES
                                                |
                                                |
                                                |
                                         INITIALIZATION   

No comments:

Post a Comment