⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread_cond_wait.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>pthread_cond_wait</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_007_1270">&nbsp;</a>NAME</h4><blockquote>pthread_cond_wait, pthread_cond_timedwait - wait on a condition</blockquote><h4><a name = "tag_000_007_1271">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;int pthread_cond_wait(pthread_cond_t *<i>cond</i>, pthread_mutex_t *<i>mutex</i>);int pthread_cond_timedwait(pthread_cond_t *<i>cond</i>,     pthread_mutex_t *<i>mutex</i>, const struct timespec *<i>abstime</i>);</code></pre></blockquote><h4><a name = "tag_000_007_1272">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>pthread_cond_wait()</i>and<i>pthread_cond_timedwait()</i>functions are used to block on a condition variable.They are called with<i>mutex</i>locked by the calling thread or undefined behaviour will result.<p>These functions atomically release<i>mutex</i>and cause the calling thread to block on the condition variable<i>cond</i>;atomically here means &quot;atomically with respect to access by another thread to the mutex and then the condition variable&quot;.That is, if another thread is able to acquire the mutexafter the about-to-block thread has released it,then a subsequent call to<i><a href="pthread_cond_signal.html">pthread_cond_signal()</a></i>or<i><a href="pthread_cond_broadcast.html">pthread_cond_broadcast()</a></i>in that thread behaves as if it were issuedafter the about-to-block thread has blocked.<p>Upon successful return, the mutex has beenlocked and is owned by the calling thread.<p>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<i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>functions may occur.Since the return from<i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>does not imply anything about the value of this predicate,the predicate should be re-evaluated upon such return.<p>The effect of using more than one mutex for concurrent<i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>operations on the same condition variable isundefined; that is, a condition variable becomes bound to a unique mutexwhen a threadwaits on the condition variable,and this (dynamic) binding ends when the wait returns.<p>A condition wait (whether timed or not) is a cancellation point.When the cancelability enable state of a thread is set toPTHREAD_CANCEL_DEFERRED,a side effect of acting upon a cancellation requestwhile in a condition wait is that the mutex is (in effect) re-acquiredbefore 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 thecall to <i>pthread_cond_wait()</i>or <i>pthread_cond_timedwait()</i>,but at that pointnotices the cancellation request and instead of returning to the callerof <i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>,starts the thread cancellation activities, which includes callingcancellation cleanup handlers.<p>A thread that has been unblocked because it has beencanceled while blocked in a call to<i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>does not consume any condition signal that may bedirected concurrently at thecondition variable if there are other threads blocked onthe condition variable.<p>The<i>pthread_cond_timedwait()</i>function is the same as<i>pthread_cond_wait()</i>except thatan error is returnedif the absolute time specified by<i>abstime</i>passes (that is, system time equals or exceeds<i>abstime</i>)before the condition<i>cond</i>is signaled or broadcasted,or if the absolute time specified by<i>abstime</i>has already been passed at the time of the call.When such time-outs occur,<i>pthread_cond_timedwait()</i>will nonetheless releaseand reacquire the mutex referenced by<i>mutex</i>.The function<i>pthread_cond_timedwait()</i>is also a cancellation point.<p>If a signal is delivered to a thread waiting for a condition variable,upon return from the signal handlerthe thread resumes waiting for the condition variableas if it was not interrupted,or it returns zero due to spurious wakeup.</blockquote><h4><a name = "tag_000_007_1273">&nbsp;</a>RETURN VALUE</h4><blockquote>Except in the case of [ETIMEDOUT],all these error checks act as if they were performed immediatelyat the beginning of processing for the functionand cause an error return,in effect, prior to modifying the state of the mutex specified by<i>mutex</i>or the condition variable specified by<i>cond</i>.<p>Upon successful completion, a value of zero is returned.Otherwise, an error number is returned to indicate the error.</blockquote><h4><a name = "tag_000_007_1274">&nbsp;</a>ERRORS</h4><blockquote>The <i>pthread_cond_timedwait()</i>function will fail if:<dl compact><dt>[ETIMEDOUT]<dd>The time specified by<i>abstime</i>to<i>pthread_cond_timedwait()</i>has passed.</dl><p>The<i>pthread_cond_wait()</i>and<i>pthread_cond_timedwait()</i>functions may fail if:<dl compact><dt>[EINVAL]<dd>The value specified by<i>cond</i>,<i>mutex</i>,or<i>abstime</i>is invalid.<dt>[EINVAL]<dd>Different mutexes were supplied for concurrent<i>pthread_cond_wait()</i>or<i>pthread_cond_timedwait()</i>operations on the same condition variable.<dt>[EINVAL]<dd>The mutex was not owned by the current thread at the time of the call.</dl><p>These functions will not return an error code of [EINTR].</blockquote><h4><a name = "tag_000_007_1275">&nbsp;</a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1276">&nbsp;</a>APPLICATION USAGE</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1277">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_1278">&nbsp;</a>SEE ALSO</h4><blockquote><i><a href="pthread_cond_signal.html">pthread_cond_signal()</a></i>,<i><a href="pthread_cond_broadcast.html">pthread_cond_broadcast()</a></i>,<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from the POSIX Threads Extension (1003.1c-1995)</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -