Block a thread on a synchronization object
#include <sys/neutrino.h> int SyncCondvarWait( sync_t * sync, sync_t * mutex ); int SyncCondvarWait_r( sync_t * sync, sync_t * mutex );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The SyncCondvarWait() and SyncCondvarWait_r() kernel calls block the calling thread on the synchronization object, sync. If more than one thread is blocked on the object, they're queued in priority order.
These functions are similar, except in the way they indicate errors. See the Returns section for details.
Instead of using these kernel calls directly, consider calling pthread_cond_timedwait() or pthread_cond_wait(). |
The blocked thread can be unblocked by any one of the following conditions:
Before returning from SyncCondvarWait(), mutex is reacquired. If mutex is locked, the thread enters into the STATE_MUTEX state waiting for mutex to be unlocked. At this point it's as though you had called SyncMutexLock(mutex).
Before returning from SyncCondvarWait(), mutex is reacquired. If mutex is locked, the thread enters into the STATE_MUTEX state waiting for mutex to be unlocked. At this point it's as though you had called SyncMutexLock(mutex).
In all cases, mutex is reacquired before the call returns. If the thread enters the STATE_MUTEX state, the rules governing SyncMutexLock() are in effect.
Condition variables are used to block a thread until a certain condition is satisfied. Spurious wakeups may occur due to timeouts, signals, and broadcast condition variable signals. Therefore, you should always reevaluate the condition, even on a successful return. The easiest way to do this is with a while loop. For example:
SyncMutexLock(&mutex); while(some_condition) { SyncCondvarWait(&condvar, &mutex); } SyncMutexUnlock(&mutex);
The only difference between these functions is the way they indicate errors:
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pthread_cond_broadcast(), pthread_cond_signal(), pthread_cond_timedwait(), pthread_cond_wait(), pthread_mutex_lock(), SignalKill(), SyncCondvarSignal(), SyncMutexLock(), SyncTypeCreate(), ThreadCancel(), TimerTimeout()