Qore Programming Language Reference Manual 1.19.2
|
The Condition class can be used For blocking a thread until a condition becomes True. More...
#include <QC_Condition.dox.h>
Public Member Methods | |
nothing | broadcast () |
Signals all threads blocked on this Condition object to wake up. More... | |
constructor () | |
Creates the Condition object. More... | |
copy () | |
Creates a new Condition object, not based on the original. More... | |
nothing | signal () |
Signals a single blocked thread to wake up. More... | |
int | wait (AbstractSmartLock lock, timeout timeout_ms=0) |
Blocks a thread until signaled; accepts an optional timeout value. More... | |
int | wait_count (AbstractSmartLock lock) |
Returns the number of threads currently blocked on this object using the AbstractSmartLock passed. More... | |
The Condition class can be used For blocking a thread until a condition becomes True.
Condition objects, when used along with an AbstractSmartLock object (such as RWLock and Mutex objects), allow Qore threads to sleep until a certain condition becomes True.
nothing Qore::Thread::Condition::broadcast | ( | ) |
Signals all threads blocked on this Condition object to wake up.
Normally this method call will be made while the same AbstractSmartLock object used for Condition::wait() calls is locked. Then, when the thread calling this method unlocks the AbstractSmartLock object, the thread(s) woken up by this call can continue executing.
CONDITION-BROADCAST-ERROR | This exception should never be thrown - it indicates a low-level error in executing the method |
Qore::Thread::Condition::constructor | ( | ) |
Creates the Condition object.
Qore::Thread::Condition::copy | ( | ) |
Creates a new Condition object, not based on the original.
nothing Qore::Thread::Condition::signal | ( | ) |
Signals a single blocked thread to wake up.
Normally this method call will be made while the same AbstractSmartLock object used for Condition::wait() calls is locked. Then, when the thread calling this method unlocks the AbstractSmartLock object, the thread woken up by this call can continue executing.
CONDITION-SIGNAL-ERROR | This exception should never be thrown - it indicates a low-level error in executing the method |
int Qore::Thread::Condition::wait | ( | AbstractSmartLock | lock, |
timeout | timeout_ms = 0 |
||
) |
Blocks a thread until signaled; accepts an optional timeout value.
Must be called with an AbstractSmartLock argument, and the AbstractSmartLock must be locked before the call. This method will atomically unlock the AbstractSmartLock object and wait on this Condition object to be woken up with a Condition::signal() or Condition::broadcast() method call in another thread. At this point, the AbstractSmartLock will be reacquired with the same state as it was acquired previously before control returns to the blocked thread. The wait condition should always be tested again when the thread is unblocked.
lock | the AbstractSmartLock object to use for synchronization on this Condition object. The AbstractSmartLock must be locked before calling this method |
timeout_ms | a timeout value to wait for the condition to be triggered; integers are interpreted as milliseconds; relative date/time values are interpreted literally (with a resolution of milliseconds). Timeout values <= 0 mean do not time out. If a timeout value > 0 is given and the call times out, the AbstractSmartLock will also be acquired when the Condition::wait() call returns and ETIMEDOUT will be returned. |
ETIMEDOUT
if a timeout has occurredCONDITION-WAIT-ERROR | This exception should never be thrown - it indicates a low-level error in executing the method |
int Qore::Thread::Condition::wait_count | ( | AbstractSmartLock | lock | ) |
Returns the number of threads currently blocked on this object using the AbstractSmartLock passed.
lock | the AbstractSmartLock object to check for blocked threads on this Condition object; the AbstractSmartLock can be in any state (locked or unlocked) for this call (does not necessarily have to be locked). |