P and V operations on general semaphores are versatile primitives capable of solving a variety of synchronization problems. But they are low-level primitives, prone to difficult-to-diagnose programming errors. (see the issues that we need to avoid in Process Interactions – those are some of the errors you might run into.)
A monitor is a high-level synchronization primitive implemented using P and V operations. A monitor encapsulates data along with functions through which the data may be accessed and manipulated.
A condition variable is a named queue on which processes can wait for some condition to become true.
The monitor should guarantee that the functions are mutually exclusive and provide condition variables such that a process can step outside of the monitor while waiting for a condition and thus not prevent other processes from entering the monitor.
A failure to do these things can cause a lock out and/or dead lock situation.
A monitor guarantees mutual exclusion, since the only way to access the data is through it’s functions.
Typically a monitor’s queue associated with a conditional variable is processed in FIFO order. Some applications require additional control over the order of process reactivation.
Therefore a priority wait can be implemented. This will be in a format of c.wait(p)
, where c is a conditional variable and p is an integer specifying a priority according to which processes blocked on c are reactivated.
Monitors was originally found on Access 2 Learn