Name
pthread_cond_signal
- unblock a thread waiting for a condition variable
Library
libc_r.lib
libpthread.lib
libthr.lib
Synopsis
|
int
pthread_cond_signal (pthread_cond_t *cond);
|
Return values
If successful, the
pthread_cond_signal
function will return zero, otherwise an error number will be returned
to indicate the error.
Detailed description
The
pthread_cond_signal
function unblocks one thread waiting for the condition variable
cond.
Examples
int rc;
struct testdata
{
pthread_mutex_t mutex;
pthread_cond_t cond;
};
static struct testdata td;
int function1()
{
if (pthread_mutex_init(&td.mutex, NULL) != 0) {
fprintf(stderr,"Fail to initialize mutex\n");
return -1;
}
if (pthread_cond_init(&td.cond, NULL) != 0) {
fprintf(stderr,"Fail to initialize cond\n");
return -1;
}
/* ....... other thread wait for signal */
/* Acquire the mutex to make sure that all waiters are currently
blocked on pthread_cond_wait */
if (pthread_mutex_lock(&td.mutex) != 0) {
fprintf(stderr,"Main: Fail to acquire mutex\n");
return -1;
}
if (pthread_mutex_unlock(&td.mutex) != 0) {
fprintf(stderr,"Main: Fail to release mutex\n");
return -1;
}
/* signal the condition to wake up all waiters */
fprintf(stderr," signal the condition\n");
rc = pthread_cond_signal(&td.cond);
if (rc != 0) {
fprintf(stderr," failed to signal the condition\n");
return -1;
}
}
Errors
The
pthread_cond_signal
function will fail if:
[EINVAL]
|
|
The value specified by
cond
is invalid.
|
See also
pthread_cond_broadcast,
pthread_cond_destroy,
pthread_cond_init,
pthread_cond_timedwait,
pthread_cond_wait
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|