module Thread: sig
.. end
Lightweight threads.
type
t
The type of thread handles.
Thread creation and termination
val create : ('a -> 'b) -> 'a -> t
Thread.create 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 Thread.create
returns the handle of the newly created thread.
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.
val thread_uncaught_exception : exn -> unit
val self : unit -> t
Return the thread currently executing.
val id : t -> int
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.
val exit : unit -> unit
Terminate prematurely the currently executing thread.
val kill : t -> unit
Terminate prematurely the thread whose handle is given.
This functionality is available only with bytecode-level threads.
Suspending threads
val delay : float -> unit
delay d
suspends the execution of the calling thread for
d
seconds. The other program threads continue to run during
this time.
val join : t -> unit
join th
suspends the execution of the calling thread
until the thread th
has terminated.
val yield : unit -> unit
Re-schedule the calling thread without suspending it.
This function can be used to give scheduling hints,
telling the scheduler that now is a good time to
switch to other threads.