Condition variable support. More...
![]() |
Condition variable support.
To avoid entering a busy waiting state, threads must be able to signal each other about events of interest. This capability is implemented as condition variables. When a function requires a particular condition to be true before it can proceed, it waits on an associated condition variable. By waiting, it gives up the lock and is removed from the set of runnable threads. Any thread that subsequently causes the condition to be true may then use the condition variable to notify a thread waiting for the condition. A thread that has been notified regains the lock and can proceed.
As an example look to the following code:
CONDITION cond = NULL; int *current_data = NULL; void push_data (int *data) { NutConditionLock(cond); current_data = data; NutSonditionSignal(cond); NutConditionUnlock(cond); } int* pop_data (void) { int* data; NutConditionLock(cond); while (!current_data) { g_cond_wait(cond); } data = current_data; current_data = NULL; NutConditionUnlock(cond); return data; }