Name
pthread_cond_wait
- wait on a condition variable
Library
libc_r.lib
libpthread.lib
libthr.lib
Synopsis
|
int
pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
|
Return values
If successful, the
pthread_cond_wait
function will return zero.
Otherwise an error number will be returned to
indicate the error.
Detailed description
The
pthread_cond_wait
function atomically blocks the current thread waiting on the condition
variable specified by
cond,
and unblocks the mutex specified by
mutex.
The waiting thread unblocks only after another thread calls
pthread_cond_signal,
or
pthread_cond_broadcast
with the same condition variable, and the current thread reacquires the lock
on
mutex.
Examples
struct testdata
{
pthread_mutex_t mutex;
pthread_cond_t cond;
};
static struct testdata td;
int rc;
/* mutex and conditional variable must be initialized */
if (pthread_mutex_lock(&td.mutex) != 0) {
fprintf(stderr,"Thread failed to acquire mutex\n");
return -1;
}
fprintf(stderr,"Thread started\n");
fprintf(stderr,"Thread is waiting for the cond\n");
rc = pthread_cond_wait(&td.cond, &td.mutex);
if (rc != 0) {
fprintf(stderr,"pthread_cond_wait return %d\n", rc);
return -1;
}
fprintf(stderr,"Thread wakened\n");
pthread_mutex_unlock(&td.mutex);
Errors
The
pthread_cond_wait
function will fail if:
[EINVAL]
|
|
The value specified by
cond
or the value specified by
mutex
is invalid.
|
[ENOMEM]
|
|
This function was not able to acquire a required resource.
|
[ETIMEDOUT]
|
|
The absolute time specified by abstime parameter occurred before the condition variable was signaled.
|
See also
pthread_cond_broadcast,
pthread_cond_destroy,
pthread_cond_init,
pthread_cond_signal,
pthread_cond_timedwait
The
pthread_cond_wait
function conforms to
-p1003.1-96.
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|