1996-09-04 07:17:43 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Caml Special Light *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1995 Institut National de Recherche en Informatique et *)
|
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* User-level threads *)
|
|
|
|
|
|
|
|
type t
|
|
|
|
|
1996-09-08 08:41:59 -07:00
|
|
|
external thread_initialize : unit -> unit = "caml_thread_initialize"
|
|
|
|
external thread_new : (unit -> unit) -> t = "caml_thread_new"
|
|
|
|
|
|
|
|
external yield : unit -> unit = "caml_thread_yield"
|
|
|
|
external self : unit -> t = "caml_thread_self"
|
|
|
|
external id : t -> int = "caml_thread_id"
|
|
|
|
external join : t -> unit = "caml_thread_join"
|
1996-09-04 07:17:43 -07:00
|
|
|
|
|
|
|
(* For new, make sure the function passed to thread_new never
|
|
|
|
raises an exception. *)
|
|
|
|
|
1997-11-25 07:29:46 -08:00
|
|
|
exception Thread_exit
|
|
|
|
|
1996-09-04 07:17:43 -07:00
|
|
|
let create fn arg =
|
|
|
|
thread_new
|
|
|
|
(fun () ->
|
|
|
|
try
|
1997-11-25 07:29:46 -08:00
|
|
|
fn arg; ()
|
|
|
|
with Thread_exit -> ()
|
|
|
|
| exn ->
|
|
|
|
Printf.eprintf "Uncaught exception in thread %d: %s\n"
|
|
|
|
(id(self())) (Printexc.to_string exn);
|
|
|
|
flush stderr)
|
|
|
|
|
|
|
|
let exit () = raise Thread_exit
|
|
|
|
|
|
|
|
(* Thread.kill is currently not implemented because there is no way
|
|
|
|
to do correct cleanup under Win32. *)
|
|
|
|
|
|
|
|
let kill th = invalid_arg "Thread.kill: not implemented"
|
1996-09-04 07:17:43 -07:00
|
|
|
|
|
|
|
(* Preemption *)
|
|
|
|
|
|
|
|
let preempt signal = yield()
|
|
|
|
|
|
|
|
(* Initialization of the scheduler *)
|
|
|
|
|
|
|
|
let _ =
|
1997-11-17 05:04:18 -08:00
|
|
|
Sys.signal 1 (Sys.Signal_handle preempt);
|
1996-09-04 07:17:43 -07:00
|
|
|
thread_initialize()
|
|
|
|
|
1996-09-09 05:25:20 -07:00
|
|
|
(* Wait functions *)
|
|
|
|
|
|
|
|
external delay: float -> unit = "caml_thread_delay"
|
|
|
|
|
1996-09-04 07:17:43 -07:00
|
|
|
let wait_read fd = ()
|
|
|
|
let wait_write fd = ()
|
1996-09-09 05:25:20 -07:00
|
|
|
|
1996-09-06 09:52:29 -07:00
|
|
|
let wait_timed_read fd delay = true
|
|
|
|
let wait_timed_write fd delay = true
|
1997-09-02 09:01:39 -07:00
|
|
|
let select rd wr ex delay = invalid_arg "Thread.select: not implemented"
|
1996-09-04 07:17:43 -07:00
|
|
|
|
|
|
|
let wait_pid p = Unix.waitpid [] p
|
1996-09-09 05:25:20 -07:00
|
|
|
|