CS::Threading::Condition Class Reference
|Notify and wake up all threads currently waiting for the condition. |
|Notify and wake up one thread waiting for the condition. |
|template<typename LockType >|
|bool||Wait (LockType &lock, csTicks timeout=0)|
|Wait for some change of condition. |
A condition variable is a synchronization primitive used to have threads wait for a shared state variable to attain a given value.
Member Function Documentation
|bool CS::Threading::Condition::Wait||(||LockType &||lock,|
|csTicks|| timeout = |
Wait for some change of condition.
Suspends the calling thread until some other thread invokes Notify() or NotifyAll() to notify a change of condition.
lock The mutex to associate with this condition. The caller must already hold a lock on the mutex before calling Wait(), and all threads waiting on the condition must be using the same mutex. The mutex must not be locked recursively within the same thread. When called, Wait() releases the caller's lock on the mutex and suspends the caller's thread. Upon return from Wait(), the caller's lock on the mutex is restored. timeout Timeout in milliseconds for the wait. A value of 0 means infinite wait.
truewhen the condition was changed, or
falseif the wait timed out.
- The reason that the mutex must not be locked recursively is because the implicit unlock performed by Wait() must actually release the mutex in order for other threads to be able to satisfy the condition. With recursively locked mutexes, there is no guarantee that the one implicit unlock operation performed by Wait() will actually release the mutex since it might have been locked multiple times within the same thread.
- Having to use a timed wait may indicate a code flaw. Try to avoid timed waits and instead fix your synchronization logic.
The documentation for this class was generated from the following file:
Generated for Crystal Space 1.4.1 by doxygen 1.7.1