A monitor is a special object, or ???abstract data type,??? that can insure that only one process or thread is active
in it at one time. A process enters the monitor by calling one of the monitor??™s methods. Once a process enters
the monitor, no other process can enter until the first process exits the monitor. If another process calls one of
the monitor??™s methods while a process is active within the monitor, the second process blocks, waiting for the
first process to exit the monitor.
Since the monitor insures mutual exclusion by virtue of the fact that only one process may be active within
it, the programmer using the monitor can dispense with worrying about semaphores or other mechanisms to
assure mutual exclusion. In fact, the first lines of code in a monitor??™s method may use a semaphore internally
to enforce the mutual exclusion, but the programmer need not be concerned with the mechanism.
In addition to insuring mutual exclusion, a monitor can be used to synchronize access by different threads
or processes by using ???condition variables??? to allow a process to wait, if some condition necessary for success
is absent at the time it is active in the monitor. Condition variables also allow the waiting process to be restarted
when the condition changes.
Pages:
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295