1995-10-30 02:21:56 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Caml Special Light *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1995 Institut National de Recherche en Informatique et *)
|
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Module [Thread]: user-level lightweight threads *)
|
|
|
|
|
|
|
|
type t
|
1996-03-05 02:12:07 -08:00
|
|
|
(* The type of thread handles. *)
|
1995-11-15 08:40:01 -08:00
|
|
|
|
|
|
|
(** Thread creation and termination *)
|
|
|
|
|
1995-10-30 02:21:56 -08:00
|
|
|
val new : ('a -> 'b) -> 'a -> t
|
1995-11-15 08:40:01 -08:00
|
|
|
(* [new funct arg] creates a new thread of control, in which the
|
|
|
|
function application [funct arg] is executed concurrently
|
|
|
|
with the other threads of the program. The application of [new]
|
1996-03-05 02:12:07 -08:00
|
|
|
returns the handle of the newly created thread.
|
1995-11-15 08:40:01 -08:00
|
|
|
The new thread terminates when the application [funct arg]
|
|
|
|
returns, either normally or by raising an uncaught exception.
|
|
|
|
In the latter case, the exception is printed on standard error,
|
|
|
|
but not propagated back to the parent thread. Similarly, the
|
|
|
|
result of the application [funct arg] is discarded and not
|
|
|
|
directly accessible to the parent thread. *)
|
1996-04-01 07:26:00 -08:00
|
|
|
external self : unit -> t = "csl_thread_self"
|
1996-03-05 02:12:07 -08:00
|
|
|
(* Return the thread currently executing. *)
|
1996-04-01 07:26:00 -08:00
|
|
|
external id : t -> int = "csl_thread_id"
|
1996-03-05 02:12:07 -08:00
|
|
|
(* Return the identifier of the given thread. A thread identifier
|
|
|
|
is an integer that identifies uniquely the thread.
|
|
|
|
It can be used to build data structures indexed by threads. *)
|
1996-04-01 07:26:00 -08:00
|
|
|
external exit : unit -> unit = "csl_thread_exit"
|
1996-03-05 02:12:07 -08:00
|
|
|
(* Terminate prematurely the currently executing thread. *)
|
1995-11-15 08:40:01 -08:00
|
|
|
|
1996-04-01 07:26:00 -08:00
|
|
|
(** Thread synchronization *)
|
1995-11-15 08:40:01 -08:00
|
|
|
|
1996-04-01 07:26:00 -08:00
|
|
|
external join : t -> unit = "csl_thread_join"
|
1995-11-16 02:59:57 -08:00
|
|
|
(* [join th] suspends the execution of the calling thread
|
|
|
|
until the thread [th] has terminated. *)
|
1996-04-01 07:26:00 -08:00
|
|
|
external detach : t -> unit = "csl_thread_detach"
|
|
|
|
(* [detach th] indicates that the thread [th] will never
|
|
|
|
be joined, and that its resources can be freed as soon
|
|
|
|
as it terminates. *)
|
|
|
|
|
|
|
|
(** Thread scheduling *)
|
|
|
|
|
|
|
|
external yield : unit -> unit = "csl_thread_yield"
|
|
|
|
(* [yield()] suggests the scheduler that this is a good point
|
|
|
|
to suspend the current thread and reactivate another one.
|
|
|
|
This is just a hint: the scheduler preempts periodically
|
|
|
|
long-running threads even if they never execute [yield()].
|
|
|
|
Using [yield()] may improve the responsiveness of the program,
|
|
|
|
though. *)
|