Monitors and Examples
Check Section 6.7 of the Dinasaur Book.
-
Concept of a Monitor: a high-level programming structure that includes private data (that is, data that are protected by the monitor), "synchronized" methods of which only one can be executed at any time, and initialization methods.
Semantics: Only one of the synchronized method can be executed on the same object; methods on different objects can be executed concurrently;
-
Conditional Variables: wait and wakeup operations;
a thread is blocked if it does a "wait" operation on a conditional variable;
a blocked thread is waken up when another thread does a "signal" on the conditional variable;
when a thread "signals" a conditional variable, it wakes up exactly one
thread if there are one or more threads waiting on the conditional variable;
when a thread "signals" a conditional variable, if there is no thread waiting
on the conditional variable, it does nothing.
-
Implementing Monitors using Semaphores (solution is in Section 6.7 of the Dinasour book)
-
Implementing Semaphores using Monitors (discussion session)