Automatic generation produced by ISE Eiffel
class CONDITION_VARIABLE General cluster: ise description: "Condition variables allow threads to synchronize based on the content of a shared data, whereas mutexes only synchronize access to the data. In other words, a condition variable is a synchronization object that enables threads to wait until a particular condition occurs. When a thread executes a wait call on a condition variable, it must hold an associated mutex (used for checking that condition). Then, it is immediately suspended and put into the waiting queue. The thread is suspended and is waiting for the condition to occur. Eventually, when the condition has occurred, a thread will signal it. Two possible scenarios: - if there are threads waiting, then one of the waiting thread will resume its execution and will get the mutex in a locked state. - if there are no threads waiting, nothing is done For the simple usage of a condition variable, it is very similar to using a semaphore. In addition you have broadcast that will resume all waiting threads at once, and wait_with_timeout that will wait only a certain amount of time before abandonning the wait. The signal and broadcast routines can be called by a thread whether or not it currently owns the mutex that threads calling wait or wait_with_timeout have associated with the condition variable during their waits. If, however, predictable scheduling behavior is required, then that mutex should be locked by the thread prior to calling signal or broadcast. Assuming shared_data an INTEGER initially set to zero, then a typical usage of condition variable to wait until shared_data becomes one, could be written as followed in thread A: mutex.lock from until shared_data = 1 loop condition_variable.wait (mutex) end mutex.unlock and in thread B: mutex.lock shared_data := 1 condition_variable.signal mutex.unlock Thread A will be blocked until thread B signal that now shared_data is 1." create: make Ancestors DISPOSABLE* Queries is_set: BOOLEAN wait_with_timeout (a_mutex: MUTEX; a_timeout_ms: INTEGER_32): BOOLEAN Commands broadcast destroy dispose signal wait (a_mutex: MUTEX) -- Generated by Eiffel Studio --
For more details: eiffel.org