Home > pthread cond timedwait example > pthread_cond_timedwait error codes

Pthread_cond_timedwait Error Codes

the interface may not be implemented on Linux. Name pthread_cond_timedwait, pthread_cond_wait - wait on a condition Synopsis #include int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict pthread_cond_timedwait example abstime); int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); Description The pthread_cond_timedwait() and pthread_cond_wait() pthread_cond_timedwait linux functions shall block on a condition variable. They shall be called with mutex locked by the calling thread or pthread_cond_timedwait return value 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 pthread_cond_timedwait timeout 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.

Pthread_cond_timedwait Example C++

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 value of this predicate, the predicate should be re-evaluated upon such return. The effect of using more than one mutex for concurrent pthread_cond_timedwait() or pthread_cond_wait() operations on the same condition variable is undefined; that is, a condition variable becomes bound to a unique mutex when a thread waits on the condition variable, and this (dynamic) binding shall end when the wait returns. A condition wait (whether timed or not) is a cancellation point. When the cancelability enable state of a thread is set to PTHREAD_CANCEL_DEFERRED, a side effect of acting upon a cancellation request while in a condition wait is that the mutex is (in effect) re-acquired before calling the first cancellation cleanup handler. The effect is as if the thread were unblocked, allowed to execute up to the point of returning from the call to pthread_cond_timedwait() or pthread_cond_wait(), but at that point not

 

Related content

pthread_cond_wait error codes

Pthread cond wait Error Codes p wait on a condition SYNOPSIS tt sup a href javascript open code 'THR' THR a sup img src images opt-start gif alt Option Start border include a pthread cond timedwait example href basedefs pthread h html pthread h a br br int pthread cond timedwait pthread cond t restrict tt i cond i tt br pthread mutex t restrict tt i mutex i tt br pthread cond wait timeout const struct timespec restrict tt i abstime i tt br int pthread cond wait pthread cond t restrict tt i cond i tt br pthread

pthread_condtimedwait error

Pthread condtimedwait Error p wait on a condition SYNOPSIS tt sup a href javascript open code 'THR' THR a sup img src images opt-start gif alt Option Start border include a href basedefs pthread h html pthread h a br br int pthread cond timedwait pthread cond t restrict tt i cond i tt br Pthread cond timedwait Example pthread mutex t restrict tt i mutex i tt br const struct timespec restrict tt i abstime i tt br int pthread cond wait pthread cond t pthread cond timedwait linux restrict tt i cond i tt br pthread mutex t