1 (***********************************************************************)
5 (* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *)
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. *)
12 (***********************************************************************)
14 (* $Id: condition.mli 4144 2001-12-07 13:41:02Z xleroy $ *)
16 (** Condition variables to synchronize between threads.
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):
26 while (* some predicate P over D is not satisfied *) do
30 if (* the predicate P over D is now satified *) then Condition.signal c;
36 (** The type of condition variables. *)
38 val create : unit -> t
39 (** Return a new condition variable. *)
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. *)
47 val signal : t -> unit
48 (** [signal c] restarts one of the processes waiting on the
49 condition variable [c]. *)
51 val broadcast : t -> unit
52 (** [broadcast c] restarts all processes waiting on the
53 condition variable [c]. *)