1995-11-05 09:27:32 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* *)
|
1995-11-14 09:12:57 -08:00
|
|
|
(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-11-14 09:12:57 -08:00
|
|
|
(* Module [Mutex]: locks for mutual exclusion *)
|
1995-11-05 09:27:32 -08:00
|
|
|
|
1995-11-15 08:40:01 -08:00
|
|
|
(* Mutexes (mutual-exclusion locks) are used to implement critical sections
|
|
|
|
and protect shared mutable data structures against concurrent accesses.
|
|
|
|
The typical use is (if [m] is the mutex associated with the data structure
|
|
|
|
[D]):
|
|
|
|
[
|
|
|
|
Mutex.lock m;
|
|
|
|
(* Critical section that operates over D *);
|
|
|
|
Mutex.unlock m
|
|
|
|
]
|
|
|
|
*)
|
|
|
|
|
1995-11-05 09:27:32 -08:00
|
|
|
type t
|
1995-11-15 08:40:01 -08:00
|
|
|
(* The type of mutexes. *)
|
1996-04-22 04:15:41 -07:00
|
|
|
val create: unit -> t
|
1995-11-15 08:40:01 -08:00
|
|
|
(* Return a new mutex. *)
|
1996-04-03 02:02:34 -08:00
|
|
|
val lock: t -> unit
|
1995-11-15 08:40:01 -08:00
|
|
|
(* Lock the given mutex. Only one thread can have the mutex locked
|
|
|
|
at any time. A thread that attempts to lock a mutex already locked
|
|
|
|
by another thread will suspend until the other thread unlocks
|
|
|
|
the mutex. *)
|
1996-04-03 02:02:34 -08:00
|
|
|
val try_lock: t -> bool
|
1995-11-15 08:40:01 -08:00
|
|
|
(* Same as [try_lock], but does not suspend the calling thread if
|
|
|
|
the mutex is already locked: just return [false] immediately
|
|
|
|
in that case. If the mutex is unlocked, lock it and
|
|
|
|
return [true]. *)
|
1996-04-03 02:02:34 -08:00
|
|
|
val unlock: t -> unit
|
1995-11-15 08:40:01 -08:00
|
|
|
(* Unlock the given mutex. Other threads suspended trying to lock
|
|
|
|
the mutex will restart. *)
|