Condition
From CometPublic
Comet supports POSIX condition variables that can be used inside monitors. For instance, the code fragment
synchronized Buffer {
int _nb;
Condition _ready;
void produce(int x) {
...
_nb++;
_ready.signal();
}
int consume() {
while(_nb <= 0) _ready.wait();
int retVal = ...;
--_nb;
}
}
Declares Buffer as a monitor (it is synchronized) with two methods: produce and consume. Since Buffer is a monitor, produce and consume are in mutual exclusion. When a thread consumes a value, it will first use the Condition variable _ready to wait until _nb becomes strictly positive (at which point there is at least one item to consume). As with POSIX conditions, blocking on the wait primitive causes the automatic and atomic release of the monitor.
The POSIX condition complies to the following API
class Condition {
void signal();
void broadcast();
void wait();
}
Naturally, Conditions must always be used inside a monitor in order to find and use the relevant mutex.

