1Mutex(3)                         OCaml library                        Mutex(3)
2
3
4

NAME

6       Mutex - Locks for mutual exclusion.
7

Module

9       Module   Mutex
10

Documentation

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 ac‐
20       cesses.  The typical use is (if m is the mutex associated with the data
21       structure D ):
22            Mutex.lock m;
23            (* Critical section that operates over D *);
24            Mutex.unlock m
25
26
27
28
29
30
31       type t
32
33
34       The type of mutexes.
35
36
37
38       val create : unit -> t
39
40       Return a new mutex.
41
42
43
44       val lock : t -> unit
45
46       Lock the given mutex. Only one thread can have the mutex locked at  any
47       time.  A thread that attempts to lock a mutex already locked by another
48       thread will suspend until the other thread unlocks the mutex.
49
50
51       Before4.12
52
53       Sys_error was not raised for recursive locking (platform-dependent  be‐
54       haviour)
55
56
57
58       Raises  Sys_error  if the mutex is already locked by the thread calling
59       Mutex.lock .
60
61
62
63       val try_lock : t -> bool
64
65       Same as Mutex.lock , but does not suspend the calling thread if the mu‐
66       tex  is  already locked: just return false immediately in that case. If
67       the mutex is unlocked, lock it and return true .
68
69
70
71       val unlock : t -> unit
72
73       Unlock the given mutex. Other threads suspended trying to lock the  mu‐
74       tex  will  restart.   The mutex must have been previously locked by the
75       thread that calls Mutex.unlock .
76
77
78       Before4.12
79
80       Sys_error was not raised when unlocking an unlocked mutex or  when  un‐
81       locking a mutex from a different thread.
82
83
84
85       Raises  Sys_error  if  the  mutex  is unlocked or was locked by another
86       thread.
87
88
89
90
91
92OCamldoc                          2021-07-22                          Mutex(3)
Impressum