TQWaitConditions allow a thread to tell other threads that some sort of condition has been met; one or many threads can block waiting for a TQWaitCondition to set a condition with wakeOne() or wakeAll(). Use wakeOne() to wake one randomly selected event or wakeAll() to wake them all. For example, say we have three tasks that should be performed every time the user presses a key; each task could be split into a thread, each of which would have a run() body like this:
// Causes any thread in key_pressed.wait() to return from
.br
// that method and continue processing
.br
key_pressed.wakeAll();
.br
}
.br
.fi
.PP
Note that the order the three threads are woken up in is undefined, and that if some or all of the threads are still in do_something() when the key is pressed, they won't be woken up (since they're not waiting on the condition variable) and so the task will not be performed for that key press. This can be avoided by, for example, doing something like this:
Wait on the thread event object. The thread calling this will block until either of these conditions is met:
.TP
Another thread signals it using wakeOne() or wakeAll(). This function will return TRUE in this case.
.TP
\fItime\fR milliseconds has elapsed. If \fItime\fR is ULONG_MAX (the default), then the wait will never timeout (the event must be signalled). This function will return FALSE if the wait timed out.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Release the locked \fImutex\fR and wait on the thread event object. The \fImutex\fR must be initially locked by the calling thread. If \fImutex\fR is not in a locked state, this function returns immediately. If \fImutex\fR is a recursive mutex, this function returns immediately. The \fImutex\fR will be unlocked, and the calling thread will block until either of these conditions is met:
.TP
Another thread signals it using wakeOne() or wakeAll(). This function will return TRUE in this case.
.TP
\fItime\fR milliseconds has elapsed. If \fItime\fR is ULONG_MAX (the default), then the wait will never timeout (the event must be signalled). This function will return FALSE if the wait timed out.
.PP
The mutex will be returned to the same locked state. This function is provided to allow the atomic transition from the locked state to the wait state.
This wakes all threads waiting on the TQWaitCondition. The order in which the threads are woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted.
This wakes one thread waiting on the TQWaitCondition. The thread that is woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted.