1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** Locks for mutual exclusion.
17
18 Mutexes (mutual-exclusion locks) are used to implement critical sections
19 and protect shared mutable data structures against concurrent accesses.
20 The typical use is (if [m] is the mutex associated with the data structure
21 [D]):
22 {[
23 Mutex.lock m;
24 (* Critical section that operates over D *);
25 Mutex.unlock m
26 ]}
27 *)
28
29 type t
30 (** The type of mutexes. *)
31
32 val create : unit -> t
33 (** Return a new mutex. *)
34
35 val lock : t -> unit
36 (** Lock the given mutex. Only one thread can have the mutex locked
37 at any time. A thread that attempts to lock a mutex already locked
38 by another thread will suspend until the other thread unlocks
39 the mutex. *)
40
41 val try_lock : t -> bool
42 (** Same as {!Mutex.lock}, but does not suspend the calling thread if
43 the mutex is already locked: just return [false] immediately
44 in that case. If the mutex is unlocked, lock it and
45 return [true]. *)
46
47 val unlock : t -> unit
48 (** Unlock the given mutex. Other threads suspended trying to lock
49 the mutex will restart. *)
50