134 lines
2.1 KiB
HTML
134 lines
2.1 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Mutex</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Mutex</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>
|
|
|
|
Mutex - Locks for mutual exclusion.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Mutex
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Mutex</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Locks for mutual exclusion.
|
|
<P>
|
|
Mutexes (mutual-exclusion locks) are used to implement critical sections
|
|
and protect shared mutable data structures against concurrent accesses.
|
|
The typical use is (if
|
|
<B>m</B>
|
|
|
|
is the mutex associated with the data structure
|
|
<B>D</B>
|
|
|
|
):
|
|
<B>Mutex.lock m;</B>
|
|
|
|
|
|
|
|
<B>(* Critical section that operates over D *);</B>
|
|
|
|
<B>Mutex.unlock m</B>
|
|
|
|
<B></B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type t </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of mutexes.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>unit -> t</B>
|
|
|
|
<P>
|
|
Return a new mutex.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lock </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
Lock the given mutex. Only one thread can have the mutex locked
|
|
at any time. A thread that attempts to lock a mutex already locked
|
|
by another thread will suspend until the other thread unlocks
|
|
the mutex.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val try_lock </I>
|
|
|
|
:
|
|
<B>t -> bool</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Mutex.lock</B>
|
|
|
|
, but does not suspend the calling thread if
|
|
the mutex is already locked: just return
|
|
<B>false</B>
|
|
|
|
immediately
|
|
in that case. If the mutex is unlocked, lock it and
|
|
return
|
|
<B>true</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val unlock </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
Unlock the given mutex. Other threads suspended trying to lock
|
|
the mutex will restart.
|
|
<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:48 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|