295,19 → 295,24 |
and operate in a way similar to the example below. A thread waiting for |
the condition becoming true does the following:</para> |
|
<para><programlisting language="C"><function>mutex_lock</function>(<varname>mtx</varname>); |
<example> |
<title>Use of <code>condvar_wait_timeout</code>.</title> |
<programlisting language="C"><function>mutex_lock</function>(<varname>mtx</varname>); |
while (!<varname>condition</varname>) |
<function>condvar_wait_timeout</function>(<varname>cv</varname>, <varname>mtx</varname>); |
/* <remark>the condition is true, do something</remark> */ |
<function>mutex_unlock</function>(<varname>mtx</varname>);</programlisting></para> |
<function>mutex_unlock</function>(<varname>mtx</varname>);</programlisting> |
</example> |
|
<para>A thread that causes the condition become true signals this event |
like this:</para> |
|
<para><programlisting><function>mutex_lock</function>(<varname>mtx</varname>); |
<example> |
<title>Use of <code>condvar_signal</code>.</title> |
<programlisting><function>mutex_lock</function>(<varname>mtx</varname>); |
<varname>condition</varname> = <constant>true</constant>; |
<function>condvar_signal</function>(<varname>cv</varname>); /* <remark>condvar_broadcast(cv);</remark> */ |
<function>mutex_unlock</function>(<varname>mtx</varname>);</programlisting></para> |
<function>mutex_unlock</function>(<varname>mtx</varname>);</programlisting></example> |
|
<para>The wait operation, <code>condvar_wait_timeout</code>, always puts |
the calling thread to sleep. The thread then sleeps until another thread |