]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/otherlibs/systhreads/condition.mli
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / otherlibs / systhreads / condition.mli
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                           Objective Caml                            *)
4 (*                                                                     *)
5 (*         Xavier Leroy and Damien Doligez, INRIA Rocquencourt         *)
6 (*                                                                     *)
7 (*  Copyright 1996 Institut National de Recherche en Informatique et   *)
8 (*  en Automatique.  All rights reserved.  This file is distributed    *)
9 (*  under the terms of the GNU Library General Public License, with    *)
10 (*  the special exception on linking described in file ../../LICENSE.  *)
11 (*                                                                     *)
12 (***********************************************************************)
13
14 (* $Id: condition.mli 4144 2001-12-07 13:41:02Z xleroy $ *)
15
16 (** Condition variables to synchronize between threads.
17
18    Condition variables are used when one thread wants to wait until another
19    thread has finished doing something: the former thread ``waits'' on the
20    condition variable, the latter thread ``signals'' the condition when it
21    is done. Condition variables should always be protected by a mutex.
22    The typical use is (if [D] is a shared data structure, [m] its mutex,
23    and [c] is a condition variable):
24    {[
25      Mutex.lock m;
26      while (* some predicate P over D is not satisfied *) do
27        Condition.wait c m
28      done;
29      (* Modify D *)
30      if (* the predicate P over D is now satified *) then Condition.signal c;
31      Mutex.unlock m
32    ]}
33 *)
34
35 type t
36 (** The type of condition variables. *)
37
38 val create : unit -> t
39 (** Return a new condition variable. *)
40
41 val wait : t -> Mutex.t -> unit
42 (** [wait c m] atomically unlocks the mutex [m] and suspends the
43    calling process on the condition variable [c]. The process will
44    restart after the condition variable [c] has been signalled.
45    The mutex [m] is locked again before [wait] returns. *)
46
47 val signal : t -> unit
48 (** [signal c] restarts one of the processes waiting on the 
49    condition variable [c]. *)
50
51 val broadcast : t -> unit
52 (** [broadcast c] restarts all processes waiting on the 
53    condition variable [c]. *)