1Stdlib.Mutex(3) OCaml library Stdlib.Mutex(3)
2
3
4
6 Stdlib.Mutex - no description
7
9 Module Stdlib.Mutex
10
12 Module Mutex
13 : (module Stdlib__Mutex)
14
15
16
17
18
19
20
21 type t
22
23
24 The type of mutexes.
25
26
27
28 val create : unit -> t
29
30 Return a new mutex.
31
32
33
34 val lock : t -> unit
35
36 Lock the given mutex. Only one thread can have the mutex locked at any
37 time. A thread that attempts to lock a mutex already locked by another
38 thread will suspend until the other thread unlocks the mutex.
39
40
41 Before4.12
42
43 Sys_error was not raised for recursive locking (platform-dependent be‐
44 haviour)
45
46
47
48 Raises Sys_error if the mutex is already locked by the thread calling
49 Mutex.lock .
50
51
52
53 val try_lock : t -> bool
54
55 Same as Mutex.lock , but does not suspend the calling thread if the mu‐
56 tex is already locked: just return false immediately in that case. If
57 the mutex is unlocked, lock it and return true .
58
59
60
61 val unlock : t -> unit
62
63 Unlock the given mutex. Other threads suspended trying to lock the mu‐
64 tex will restart. The mutex must have been previously locked by the
65 thread that calls Mutex.unlock .
66
67
68 Before4.12
69
70 Sys_error was not raised when unlocking an unlocked mutex or when un‐
71 locking a mutex from a different thread.
72
73
74
75 Raises Sys_error if the mutex is unlocked or was locked by another
76 thread.
77
78
79
80
81
82OCamldoc 2023-07-20 Stdlib.Mutex(3)