File: condition.mli

package info (click to toggle)
ocaml 3.12.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 25,412 kB
  • sloc: ml: 245,686; ansic: 39,092; sh: 5,924; asm: 5,371; lisp: 4,963; makefile: 3,150; perl: 82; fortran: 21; sed: 19; cs: 9; tcl: 2
file content (53 lines) | stat: -rw-r--r-- 2,292 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*         Xavier Leroy and Damien Doligez, INRIA Rocquencourt         *)
(*                                                                     *)
(*  Copyright 1996 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the GNU Library General Public License, with    *)
(*  the special exception on linking described in file ../../LICENSE.  *)
(*                                                                     *)
(***********************************************************************)

(* $Id: condition.mli 9547 2010-01-22 12:48:24Z doligez $ *)

(** Condition variables to synchronize between threads.

   Condition variables are used when one thread wants to wait until another
   thread has finished doing something: the former thread ``waits'' on the
   condition variable, the latter thread ``signals'' the condition when it
   is done. Condition variables should always be protected by a mutex.
   The typical use is (if [D] is a shared data structure, [m] its mutex,
   and [c] is a condition variable):
   {[
     Mutex.lock m;
     while (* some predicate P over D is not satisfied *) do
       Condition.wait c m
     done;
     (* Modify D *)
     if (* the predicate P over D is now satified *) then Condition.signal c;
     Mutex.unlock m
   ]}
*)

type t
(** The type of condition variables. *)

val create : unit -> t
(** Return a new condition variable. *)

val wait : t -> Mutex.t -> unit
(** [wait c m] atomically unlocks the mutex [m] and suspends the
   calling process on the condition variable [c]. The process will
   restart after the condition variable [c] has been signalled.
   The mutex [m] is locked again before [wait] returns. *)

val signal : t -> unit
(** [signal c] restarts one of the processes waiting on the
   condition variable [c]. *)

val broadcast : t -> unit
(** [broadcast c] restarts all processes waiting on the
   condition variable [c]. *)