1Mutex(3) OCaml library Mutex(3)
2
3
4
6 Mutex - Locks for mutual exclusion.
7
9 Module Mutex
10
12 Module Mutex
13 : sig end
14
15
16 Locks for mutual exclusion.
17
18 Mutexes (mutual-exclusion locks) are used to implement critical sec‐
19 tions and protect shared mutable data structures against concurrent
20 accesses. The typical use is (if m is the mutex associated with the
21 data structure D ): Mutex.lock m; (* Critical section that operates
22 over D *); Mutex.unlock m
23
24
25
26
27
28
29 type t
30
31
32 The type of mutexes.
33
34
35
36 val create : unit -> t
37
38 Return a new mutex.
39
40
41
42 val lock : t -> unit
43
44 Lock the given mutex. Only one thread can have the mutex locked at any
45 time. A thread that attempts to lock a mutex already locked by another
46 thread will suspend until the other thread unlocks the mutex.
47
48
49
50 val try_lock : t -> bool
51
52 Same as Mutex.lock , but does not suspend the calling thread if the
53 mutex is already locked: just return false immediately in that case. If
54 the mutex is unlocked, lock it and return true .
55
56
57
58 val unlock : t -> unit
59
60 Unlock the given mutex. Other threads suspended trying to lock the
61 mutex will restart.
62
63
64
65
66
67OCamldoc 2018-07-14 Mutex(3)