Name
NAME
pthread_cond_timedwait, pthread_cond_wait — wait on a condition
SYNOPSIS
THR #include <pthread.h> int pthread_cond_timedwait(pthread_cond_t *restrictcond
, pthread_mutex_t *restrictmutex
, const struct timespec *restrictabstime
); int pthread_cond_wait(pthread_cond_t *restrictcond
, pthread_mutex_t *restrictmutex
);
DESCRIPTION
The pthread_cond_timedwait() and pthread_cond_wait() functions shall block on a condition variable. They shall be called with mutex locked by the calling thread or undefined behavior results.
These functions atomically release mutex and cause the calling thread to block on the condition variable cond; atomically here means "atomically with respect to access by another thread to the mutex and then the condition variable". That is, if another thread is able to acquire the mutex after the about-to-block thread has released it, then a subsequent call to pthread_cond_broadcast() or pthread_cond_signal() in that thread shall behave as if it were issued after the about-to-block thread has blocked.
Upon successful return, the mutex shall have been locked and shall be owned by the calling thread.
When using condition variables there is always a Boolean predicate involving shared variables associated with each condition wait that is true if the thread should proceed. Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur. Since the return from pthread_cond_timedwait() or pthread_cond_wait() does not imply anything about the ...
Get Professional Multicore Programming: Design and Implementation for C++ Developers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.