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):  Mutex.lock  m;  while  (*  some
24       predicate  P  over D is not satisfied *) do Condition.wait c m done; (*
25       Modify D *) if (* the predicate P over D is now satisfied *) then  Con‐
26       dition.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-07-30                      Condition(3)
Impressum