al_wait_cond
void al_wait_cond(ALLEGRO_COND *cond, ALLEGRO_MUTEX *mutex)
Introduced in 5.0.0
On entering this function, mutex
must be locked by the calling thread. The function will atomically release mutex
and block on cond
. The function will return when cond
is "signalled", acquiring the lock on the mutex in the process.
Example of proper use:
al_lock_mutex(mutex);
while (something_not_true) {
al_wait_cond(cond, mutex);
}
do_something();
al_unlock_mutex(mutex);
The mutex should be locked before checking the condition, and should be rechecked al_wait_cond returns. al_wait_cond can return for other reasons than the condition becoming true (e.g. the process was signalled). If multiple threads are blocked on the condition variable, the condition may no longer be true by the time the second and later threads are unblocked. Remember not to unlock the mutex prematurely.
See also: al_wait_cond_until, al_broadcast_cond, al_signal_cond.
Examples: ex_threads2
Most helpful discussions:
- Synchronizing Threads
- Allegro 5.2.1.1 released!
- Thread problem
- shows error when creating class DATA in Xcode for c project
- Simple C++ video player for non-photographic animation
- Android: Rotation issues and Soft keys
- Allegro 5 threads
- [A5] simple multithread code acts weird
- The Community Needs You. New Tutorial (Threads)
- Allegro 5 Threading Interface