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
20       accesses.   The  typical  use is (if m is the mutex associated with the
21       data 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
52       val try_lock : t -> bool
53
54       Same as Mutex.lock , but does not suspend the  calling  thread  if  the
55       mutex is already locked: just return false immediately in that case. If
56       the mutex is unlocked, lock it and return true .
57
58
59
60       val unlock : t -> unit
61
62       Unlock the given mutex. Other threads  suspended  trying  to  lock  the
63       mutex will restart.
64
65
66
67
68
69OCamldoc                          2020-09-01                          Mutex(3)
Impressum