#include <cat/cat.h>
#include <cat/catmutex.h>
void catmutex_cond_wait(CATCOND *c, CATMUTEX *m);
On return, the variable may have been signalled and the mutex is held by this thread.
Condition variables are used with a mutex and an arbitrary condition. The mutex is used to protect the condition, both when changing it and when testing it.
The mutex must be held while modifying or testing the condition.
catmutex_lock(&mutex); while ( condition is false ) { catmutex_cond_wait(&condvar, &mutex); }
/* condition is true, mutex is held. */
catmutex_unlock(&mutex);
Whenever the condition is changed, do something like:
catmutex_lock(&mutex);
/* Modify condition */
catmutex_unlock(&mutex); catmutex_cond_signal(&cond);
If condition above would be ``testing whether or not an integer is greater than zero,'' the example would implement a counting semaphore.