pthread_cond_wait.txt
来自「Pthread lib库完整说明文档」· 文本 代码 · 共 135 行
TXT
135 行
--------------------------------------------------------------------------------AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1--------------------------------------------------------------------------------pthread_cond_wait or pthread_cond_timedwait SubroutinePurposeBlocks the calling thread on a condition.LibraryThreads Library (libpthreads.a)Syntax#include <pthread.h>int pthread_cond_wait (pthread_cond_t *cond);int pthread_cond_timedwait ( pthread_cond_t *cond, pthread_mutex_t *mutex, conststruct timespec *abstime);DescriptionThe pthread_cond_wait and pthread_cond_timedwait functions are used to block on acondition variable. They are called with mutex locked by the calling thread orundefined behaviour will result.These functions atomically release mutex and cause the calling thread to block onthe condition variable cond; atomically here means''atomically with respect toaccess 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 threadhas released it, then a subsequent call to pthread_cond_signal orpthread_cond_broadcast in that thread behaves as if it were issued after theabout-to-block thread has blocked.Upon successful return, the mutex has been locked and is owned by the callingthread.When using condition variables there is always a boolean predicate involvingshared variables associated with each condition wait that is true if the threadshould proceed. Spurious wakeups from the pthread_cond_wait orpthread_cond_timedwait functions may occur. Since the return frompthread_cond_wait or pthread_cond_timedwait does not imply anything about thevalue of this predicate, the predicate should be re-evaluated upon such return.The effect of using more than one mutex for concurrent pthread_cond_wait orpthread_cond_timedwait operations on the same condition variable is undefined;that is, a condition variable becomes bound to a unique mutex when a thread waitson the condition variable, and this (dynamic) binding ends when the wait returns.A condition wait (whether timed or not) is a cancellation point. When thecancelability enable state of a thread is set to PTHREAD_CANCEL_DEFERRED, a sideeffect of acting upon a cancellation request while in a condition wait is thatthe mutex is (in effect) re-acquired before calling the first cancellationcleanup handler. The effect is as if the thread were unblocked, allowed toexecute up to the point of returning from the call to pthread_cond_wait orpthread_cond_timedwait, but at that point notices the cancellation request andinstead of returning to the caller of pthread_cond_wait orpthread_cond_timedwait, starts the thread cancellation activities, which includescalling cancellation cleanup handlers.A thread that has been unblocked because it has been canceled while blocked in acall to pthread_cond_wait or pthread_cond_timedwait does not consume anycondition signal that may be directed concurrently at the condition variable ifthere are other threads blocked on the condition variable.The pthread_cond_timedwait function is the same as pthread_cond_wait except thatan error is returned if the absolute time specified by abstime passes (that is,system time equals or exceeds abstime) before the condition cond is signaled orbroadcasted, or if the absolute time specified by abstime has already been passedat the time of the call. When such time-outs occur, pthread_cond_timedwait willnonetheless release and reacquire the mutex referenced by mutex. The functionpthread_cond_timedwait is also a cancellation point.If a signal is delivered to a thread waiting for a condition variable, uponreturn from the signal handler the thread resumes waiting for the conditionvariable as if it was not interrupted, or it returns zero due to spurious wakeup.Parameterscondition Specifies the condition variable to wait on.mutex Specifies the mutex used to protect the condition variable. The mutex mustbe locked when the subroutine is called.timeout Points to the absolute time structure specifying the blocked statetimeout.Return ValuesExcept in the case of ETIMEDOUT, all these error checks act as if they wereperformed immediately at the beginning of processing for the function and causean error return, in effect, prior to modifying the state of the mutex specifiedby mutex or the condition variable specified by cond.Upon successful completion, a value of zero is returned. Otherwise, an errornumber is returned to indicate the error.Error CodesThe pthread_cond_timedwait function will fail if:ETIMEDOUT The time specified by abstime to pthread_cond_timedwait has passed.The pthread_cond_wait and pthread_cond_timedwait functions may fail if:EINVAL The value specified by cond, mutex,orabstime is invalid.EINVAL Different mutexes were supplied for concurrent pthread_cond_wait orpthread_cond_timedwait operations on the same condition variable.EINVAL The mutex was not owned by the current thread at the time of the call.These functions will not return an error code of EINTR.Implementation SpecificsThese subroutines are part of the Base Operating System (BOS) Runtime.Related InformationThe pthread_cond_signal or pthread_cond_broadcast subroutine, the pthread.h file.Using Condition Variables in AIX Version 4.3 General Programming Concepts:Writing and Debugging Programs.Threads Library Quick Reference in AIX Version 4.3 General Programming Concepts:Writing and Debugging Programs.--------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?