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

NAME

6       Condition - Condition variables to synchronize between threads.
7

Module

9       Module   Condition
10

Documentation

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  'waits'
20       on  the  condition  variable, the latter thread 'signals' the condition
21       when it is done. Condition variables should always be  protected  by  a
22       mutex.   The  typical  use  is  (if D is a shared data structure, m its
23       mutex, and c is a condition variable):
24            Mutex.lock m;
25            while (* some predicate P over D is not satisfied *) do
26              Condition.wait c m
27            done;
28            (* Modify D *)
29            if (* the predicate P over D is now satisfied *) then Condition.signal c;
30            Mutex.unlock m
31
32
33
34
35
36
37       type t
38
39
40       The type of condition variables.
41
42
43
44       val create : unit -> t
45
46       Return a new condition variable.
47
48
49
50       val wait : t -> Mutex.t -> unit
51
52
53       wait c m atomically unlocks  the  mutex  m  and  suspends  the  calling
54       process  on  the  condition variable c . The process will restart after
55       the condition variable c has been signalled.  The  mutex  m  is  locked
56       again before wait returns.
57
58
59
60       val signal : t -> unit
61
62
63       signal  c  restarts one of the processes waiting on the condition vari‐
64       able c .
65
66
67
68       val broadcast : t -> unit
69
70
71       broadcast c restarts all processes waiting on the condition variable  c
72       .
73
74
75
76
77
78OCamldoc                          2020-09-01                      Condition(3)
Impressum