cnd_wait()

Wait on a condition variable

Synopsis:

#include <threads.h>

int cnd_wait( cnd_t *cond,
              mtx_t *mutex );

Arguments:

cond
A pointer to the cnd_t object that you want the threads to block on.
mutex
The mutex that you want to unlock.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The cnd_wait() function blocks the calling thread on the condition variable cond, and unlocks the associated mutex mutex. The calling thread must have locked mutex before waiting on the condition variable. On return from the function, the mutex is again locked and owned by the calling thread.

The calling thread is blocked until either another thread performs a signal or broadcast on the condition variable, a signal is delivered to the thread, or the thread is canceled (waiting on a condition variable is a cancellation point). In all cases, the thread reacquires the mutex before being unblocked.

If a thread that's blocked on a condition variable is canceled, the thread reacquires the mutex that's guarding the condition variable, so that the thread's cleanup handlers run in the same state as the critical code before and after the call to this function. If some other thread owns the lock, the canceled thread blocks until the mutex is available.

Note:
  • Don't use a recursive mutex with condition variables.
  • Make sure that the thread's cleanup handlers unlock the mutex.
  • This function can interfere with the kernel's efforts to manage power usage. For more information, see the Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide.

Returns:

thrd_success
Success, or the call was interrupted by a signal.
thrd_error
An error occurred.

Classification:

C11

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes