A monitor is a structured way of combining synchronization and data, encapsulating data, methods, and synchronization in a single modular package in the same way that a class encapsulates data and methods.
More generally, this combination of methods, mutual exclusion locks, and condition objects is called a monitor.
The traditional way of seperating synchronization and data is cumbersome when implementing, for example:
mutex.lock();
try {
queue.enq(x)
} finally {
mutex.unlock();
}
If the queue is bounded, then we may be freezed at line 3 forever, since perhaps no other thread can operate on the queue.
A more sensible approach is to allow each queue to manage its own synchronization. The queue itself has its own internal lock, acquired by each method when it is called and released when it returns.
The different decisions on whether the signaler or the signalee will hold the lock after the CV is signaled result in different types of monitors.
In summary, the signaling thread will be blocked until the signaled thread released the lock.
<aside> 💡 Merits