cond_wait(3synch) cond_wait(3synch)
NAME
cond_wait - wait on a condition variable
SYNOPSIS
cc [options] -Kthread file
#include <synch.h>
int cond_wait(cond_t *cond, mutex_t *mutex);
Parameters
cond pointer to the condition variable to wait for
mutex pointer to a locked mutex
DESCRIPTION
cond_wait blocks the calling thread at the condition variable
pointed to by cond to wait for the occurrence of a condition.
The calling thread must lock the mutual exclusion lock (mutex)
pointed to by mutex before calling cond_wait, otherwise the
behavior is unpredictable.
cond_wait automatically releases the mutex, and waits on the
condition variable cond. When the condition is signaled
cond_wait reacquires the mutex and returns to the caller. The
wait can also be interrupted by a UNIX system signal, in which
case mutex is reacquired, the signal handler is called, and
cond_wait returns EINTR.
The calling thread can resume execution when the condition is
signaled or broadcast, or when interrupted. The logical
condition should be checked on return, as a return may not
have been caused by a change in the condition.
cond Parameter
The condition variable denoted by cond must previously have
been initialized (see cond_init).
mutex Parameter
mutex is a mutual exclusion variable protecting a shared
resource associated with the condition represented by the
condition variable, cond. The calling thread must lock mutex
before calling cond_wait, otherwise the behavior is
unpredictable.
Return Values
cond_wait returns zero for success and an error number for
failure, as described below.
Copyright 1994 Novell, Inc. Page 1
cond_wait(3synch) cond_wait(3synch)
Errors
If any of the following conditions is detected, cond_wait
fails and returns the corresponding value:
EINTR The wait was interrupted by a UNIX system signal.
EINVAL Invalid argument specified.
USAGE
See the description of how to use condition variables under
USAGE on cond_init(3synch).
Because the condition can change between the time the
condition is signaled and the mutex is re-locked, the calling
thread must always re-check the condition upon return from
cond_wait.
REFERENCES
condition(3synch), cond_broadcast(3synch),
cond_destroy(3synch), cond_init(3synch), cond_signal(3synch),
cond_timedwait(3synch), sema_init(3synch), sema_post(3synch),
sema_trywait(3synch), sema_wait(3synch), synch(3synch)
Copyright 1994 Novell, Inc. Page 2