Module Thread
Lightweight threads.
Thread creation and termination
val create : ('a -> 'b) -> 'a -> t
Thread.create funct arg
creates a new thread of control, in which the function applicationfunct arg
is executed concurrently with the other threads of the program. The application ofThread.create
returns the handle of the newly created thread. The new thread terminates when the applicationfunct 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 applicationfunct arg
is discarded and not directly accessible to the parent thread.
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 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 ford
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 threadth
has terminated.
val wait_read : Unix.file_descr -> unit
See
Thread.wait_write
.
val wait_write : Unix.file_descr -> unit
Suspend the execution of the calling thread until at least one character or EOF is available for reading (
Thread.wait_read
) or one character can be written without blocking (wait_write
) on the given Unix file descriptor.
val wait_timed_read : Unix.file_descr -> float -> bool
val wait_timed_write : Unix.file_descr -> float -> bool
Same as
Thread.wait_read
andThread.wait_write
, but wait for at most the amount of time given as second argument (in seconds). Returntrue
if the file descriptor is ready for input/output andfalse
if the timeout expired.
val select : Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
Suspend the execution of the calling thread until input/output becomes possible on the given Unix file descriptors. The arguments and results have the same meaning as for
Unix.select
.
val wait_pid : int -> int * Unix.process_status
wait_pid p
suspends the execution of the calling thread until the Unix process specified by the process identifierp
terminates. A pidp
of-1
means wait for any child. A pid of0
means wait for any child in the same process group as the current process. Negative pid arguments represent process groups. Returns the pid of the child caught and its termination status, as perUnix.wait
.
val wait_signal : int list -> int
wait_signal sigs
suspends the execution of the calling thread until the process receives one of the signals specified in the listsigs
. It then returns the number of the signal received. Signal handlers attached to the signals insigs
will not be invoked. Do not callwait_signal
concurrently from several threads on the same signals.