June 2012
Intermediate to advanced
536 pages
14h 25m
English
Monitors are a structured way of combining synchronization and data. A class encapsulates both data and methods in the same way that a monitor combines data, methods, and synchronization in a single modular package.
Here is why modular synchronization is important. Let us imagine our application has two threads, a producer and a consumer, that communicate through a shared FIFO queue. We could have the threads share two objects: an unsynchronized queue, and a lock to protect the queue. The producer looks something like this:
mutex.lock();
try {
queue.enq(x)
} finally {
mutex.unlock();
}
This is no way to run a railroad. Suppose the queue is bounded, meaning that an attempt to add an item ...
Read now
Unlock full access