423 lines
6.6 KiB
HTML
423 lines
6.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Thread</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Thread</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Thread - Lightweight threads for Posix 1003.1c and Win32.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Thread
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Thread</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Lightweight threads for Posix
|
|
<B>1003.1c</B>
|
|
|
|
and Win32.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type t </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of thread handles.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Thread creation and termination</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>('a -> 'b) -> 'a -> t</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Thread.create funct arg</B>
|
|
|
|
creates a new thread of control,
|
|
in which the function application
|
|
<B>funct arg</B>
|
|
|
|
is executed concurrently with the other threads of the program.
|
|
The application of
|
|
<B>Thread.create</B>
|
|
|
|
returns the handle of the newly created thread.
|
|
The new thread terminates when the application
|
|
<B>funct arg</B>
|
|
|
|
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
|
|
<B>funct arg</B>
|
|
|
|
is discarded and not
|
|
directly accessible to the parent thread.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val self </I>
|
|
|
|
:
|
|
<B>unit -> t</B>
|
|
|
|
<P>
|
|
Return the thread currently executing.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val id </I>
|
|
|
|
:
|
|
<B>t -> int</B>
|
|
|
|
<P>
|
|
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.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val exit </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Terminate prematurely the currently executing thread.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val kill </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
Terminate prematurely the thread whose handle is given.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Suspending threads</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val delay </I>
|
|
|
|
:
|
|
<B>float -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>delay d</B>
|
|
|
|
suspends the execution of the calling thread for
|
|
<B>d</B>
|
|
|
|
seconds. The other program threads continue to run during
|
|
this time.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val join </I>
|
|
|
|
:
|
|
<B>t -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>join th</B>
|
|
|
|
suspends the execution of the calling thread
|
|
until the thread
|
|
<B>th</B>
|
|
|
|
has terminated.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_read </I>
|
|
|
|
:
|
|
<B>Unix.file_descr -> unit</B>
|
|
|
|
<P>
|
|
See
|
|
<B>Thread.wait_write</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_write </I>
|
|
|
|
:
|
|
<B>Unix.file_descr -> unit</B>
|
|
|
|
<P>
|
|
This function does nothing in this implementation.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_timed_read </I>
|
|
|
|
:
|
|
<B>Unix.file_descr -> float -> bool</B>
|
|
|
|
<P>
|
|
See
|
|
<B>Thread.wait_timed_write</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_timed_write </I>
|
|
|
|
:
|
|
<B>Unix.file_descr -> float -> bool</B>
|
|
|
|
<P>
|
|
Suspend the execution of the calling thread until at least
|
|
one character or EOF is available for reading (
|
|
<B>wait_read</B>
|
|
|
|
) or
|
|
one character can be written without blocking (
|
|
<B>wait_write</B>
|
|
|
|
)
|
|
on the given Unix file descriptor. Wait for at most
|
|
the amount of time given as second argument (in seconds).
|
|
Return
|
|
<B>true</B>
|
|
|
|
if the file descriptor is ready for input/output
|
|
and
|
|
<B>false</B>
|
|
|
|
if the timeout expired.
|
|
<P>
|
|
These functions return immediately
|
|
<B>true</B>
|
|
|
|
in the Win32
|
|
implementation.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val select </I>
|
|
|
|
:
|
|
<B>Unix.file_descr list -></B>
|
|
|
|
<B>Unix.file_descr list -></B>
|
|
|
|
<B>Unix.file_descr list -></B>
|
|
|
|
<B>float -> Unix.file_descr list * Unix.file_descr list * Unix.file_descr list</B>
|
|
|
|
<P>
|
|
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
|
|
<B>Unix.select</B>
|
|
|
|
.
|
|
This function is not implemented yet under Win32.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_pid </I>
|
|
|
|
:
|
|
<B>int -> int * Unix.process_status</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>wait_pid p</B>
|
|
|
|
suspends the execution of the calling thread
|
|
until the process specified by the process identifier
|
|
<B>p</B>
|
|
|
|
terminates. Returns the pid of the child caught and
|
|
its termination status, as per
|
|
<B>Unix.wait</B>
|
|
|
|
.
|
|
This function is not implemented under MacOS.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val yield </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
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.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Management of signals</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
Signal handling follows the POSIX thread model: signals generated
|
|
by a thread are delivered to that thread; signals generated externally
|
|
are delivered to one of the threads that does not block it.
|
|
Each thread possesses a set of blocked signals, which can be modified
|
|
using
|
|
<B>Thread.sigmask</B>
|
|
|
|
. This set is inherited at thread creation time.
|
|
Per-thread signal masks are supported only by the system thread library
|
|
under Unix, but not under Win32, nor by the VM thread library.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val sigmask </I>
|
|
|
|
:
|
|
<B>Unix.sigprocmask_command -> int list -> int list</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>sigmask cmd sigs</B>
|
|
|
|
changes the set of blocked signals for the
|
|
calling thread.
|
|
If
|
|
<B>cmd</B>
|
|
|
|
is
|
|
<B>SIG_SETMASK</B>
|
|
|
|
, blocked signals are set to those in
|
|
the list
|
|
<B>sigs</B>
|
|
|
|
.
|
|
If
|
|
<B>cmd</B>
|
|
|
|
is
|
|
<B>SIG_BLOCK</B>
|
|
|
|
, the signals in
|
|
<B>sigs</B>
|
|
|
|
are added to
|
|
the set of blocked signals.
|
|
If
|
|
<B>cmd</B>
|
|
|
|
is
|
|
<B>SIG_UNBLOCK</B>
|
|
|
|
, the signals in
|
|
<B>sigs</B>
|
|
|
|
are removed
|
|
from the set of blocked signals.
|
|
<B>sigmask</B>
|
|
|
|
returns the set of previously blocked signals for the thread.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_signal </I>
|
|
|
|
:
|
|
<B>int list -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>wait_signal sigs</B>
|
|
|
|
suspends the execution of the calling thread
|
|
until the process receives one of the signals specified in the
|
|
list
|
|
<B>sigs</B>
|
|
|
|
. It then returns the number of the signal received.
|
|
Signal handlers attached to the signals in
|
|
<B>sigs</B>
|
|
|
|
will not
|
|
be invoked. The signals
|
|
<B>sigs</B>
|
|
|
|
are expected to be blocked before
|
|
calling
|
|
<B>wait_signal</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Thread creation and termination</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Suspending threads</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Management of signals</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|