|
Condition variable - Definition and Overview |
| Related Words: Ability, Abnormality, Adapt, Affairs, Affection, Affliction, Ailment, Allergy, Alter, Apprentice, Atrophy, Bearings, Blight |
|
|
|
A condition variable is a type representing a queue of suspended (delayed) processes or threads waiting on some condition. It can be considered as part of the monitor synchronization mechanism, and it used by a process or thread to delay until the monitor's state satisfies some condition; it is also used to awaken a delayed process when the condition becomes true.
Two basic operations are defined:
- wait: enqueue the calling process on the condition variable.
- signal: wake up one process waiting on the condition variable (if there is one). (Different implementations of signal are possible; it may be guaranteed to awaken the process at the head of the queue, or it may be simply guaranteed to awaken some process from the queue.)
Example: A monitor for the producer-consumer problem.
monitor ProducerConsumer
{
ItemType buffer[slots];
Condition bufferHasSpace, bufferHasData;
procedure putItem(ItemType & item)
{
if (itemCount == slots)
bufferHasSpace.wait();
buffer.add(item);
bufferHasData.signal();
}
procedure getItem(ItemType & item)
{
if (itemCount == 0)
bufferHasData.wait();
item = buffer.removeFirst();
bufferHasSpace.signal();
}
}
|
|
Example Usage of Condition |
 |
eptraffic: AT: 12/7/2009 5:55 PM HAZARDOUS Condition � SINGLE UNIT AT 4000 PORTER AV./DYER: FIRE(1) EN ROUTE (COURTESY OF EPPD) |
 |
lmkstrongman: I think Christmas has come early i givin two big tyres in good Condition, a chain that i would guess weights... http://bit.ly/4s6cya |
 |
FreeListAustin: Free for pickup - Ikea Leksvik table (North Austin): Free used Ikea Leksvik table, in good Condition, with minor s... http://bit.ly/7o3b6e |
|