167 lines
2.5 KiB
HTML
167 lines
2.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Condition</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Condition</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Condition - Condition variables to synchronize between threads.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Condition
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Condition</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Condition variables to synchronize between threads.
|
|
<P>
|
|
Condition variables are used when one thread wants to wait until another
|
|
thread has finished doing something: the former thread 'waits' on the
|
|
condition variable, the latter thread 'signals' the condition when it
|
|
is done. Condition variables should always be protected by a mutex.
|
|
The typical use is (if
|
|
<B>D</B>
|
|
|
|
is a shared data structure,
|
|
<B>m</B>
|
|
|
|
its mutex,
|
|
and
|
|
<B>c</B>
|
|
|
|
is a condition variable):
|
|
<B>Mutex.lock m;</B>
|
|
|
|
|
|
|
|
<B>while (* some predicate P over D is not satisfied *) do</B>
|
|
|
|
<B>Condition.wait c m</B>
|
|
|
|
<B>done;</B>
|
|
|
|
<B>(* Modify D *)</B>
|
|
|
|
<B>if (* the predicate P over D is now satisfied *) then Condition.signal c;</B>
|
|
|
|
<B>Mutex.unlock m</B>
|
|
|
|
<B></B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type t </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of condition variables.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>unit -> t</B>
|
|
|
|
<P>
|
|
Return a new condition variable.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait </I>
|
|
|
|
:
|
|
<B>t -> Mutex.t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>wait c m</B>
|
|
|
|
atomically unlocks the mutex
|
|
<B>m</B>
|
|
|
|
and suspends the
|
|
calling process on the condition variable
|
|
<B>c</B>
|
|
|
|
. The process will
|
|
restart after the condition variable
|
|
<B>c</B>
|
|
|
|
has been signalled.
|
|
The mutex
|
|
<B>m</B>
|
|
|
|
is locked again before
|
|
<B>wait</B>
|
|
|
|
returns.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val signal </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>signal c</B>
|
|
|
|
restarts one of the processes waiting on the
|
|
condition variable
|
|
<B>c</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val broadcast </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>broadcast c</B>
|
|
|
|
restarts all processes waiting on the
|
|
condition variable
|
|
<B>c</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:38 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|