1Condition(3) OCaml library Condition(3)
2
3
4
6 Condition - Condition variables to synchronize between threads.
7
9 Module Condition
10
12 Module Condition
13 : sig end
14
15
16 Condition variables to synchronize between threads.
17
18 Condition variables are used when one thread wants to wait until
19 another thread has finished doing something: the former thread
20 ``waits'' on the condition variable, the latter thread ``signals'' the
21 condition when it is done. Condition variables should always be pro‐
22 tected by a mutex. The typical use is (if D is a shared data struc‐
23 ture, m its mutex, and c is a condition variable): Mutex.lock m; while
24 (* some predicate P over D is not satisfied *) do Condition.wait c m
25 done; (* Modify D *) if (* the predicate P over D is now satisfied *)
26 then Condition.signal c; Mutex.unlock m
27
28
29
30
31
32
33 type t
34
35
36 The type of condition variables.
37
38
39
40 val create : unit -> t
41
42 Return a new condition variable.
43
44
45
46 val wait : t -> Mutex.t -> unit
47
48
49 wait c m atomically unlocks the mutex m and suspends the calling
50 process on the condition variable c . The process will restart after
51 the condition variable c has been signalled. The mutex m is locked
52 again before wait returns.
53
54
55
56 val signal : t -> unit
57
58
59 signal c restarts one of the processes waiting on the condition vari‐
60 able c .
61
62
63
64 val broadcast : t -> unit
65
66
67 broadcast c restarts all processes waiting on the condition variable c
68 .
69
70
71
72
73
74OCamldoc 2019-02-02 Condition(3)