Module Core__.Core_thread
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
Thread creation and termination
val create : on_uncaught_exn:[ `Kill_whole_process | `Print_to_stderr ] -> ('a -> unit) -> '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 application
funct arg
returns, either normally or by raising an uncaught exception.In the latter case, behavior is controlled by
on_uncaught_exn
. If`Print_to_stderr
is selected, the exception is printed on standard error, but not propagated back to the parent thread. If`Kill_whole_process
is selected, the exception is printed to stderr and then the process exits with code 1 (after having runat_exit
callbacks, etc.).
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.
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_write : Unix.file_descr -> unit
Suspend the execution of the calling thread until at least one character is available for reading (
Thread
.wait_read) or one character can be written without blocking (wait_write
) on the given Unix file descriptor.
Management of signals
val sigmask : Core.Signal.sigprocmask_command -> Core.Signal.t list -> Core.Signal.t list
sigmask cmd sigs
changes the set of blocked signals for the calling thread. Ifcmd
is`Set
, blocked signals are set to those in the listsigs
. Ifcmd
is`Block
, the signals insigs
are added to the set of blocked signals. Ifcmd
is`Unblock
, the signals insigs
are removed from the set of blocked signals.sigmask
returns the set of previously blocked signals for the thread.
val wait_signal : Core.Signal.t 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. The signalssigs
are expected to be blocked before callingwait_signal
.
val threads_have_been_created : unit -> bool
true
iff Thread.create has ever been called, even if there is currently only one running thread.
Non-portable pthread extensions
The following operations may not be supported on all platforms. Before you can use them, you must first check that they do not contain error values. For example, if you wanted to use setaffinity_self_exn
then you would first do:
let setaffinity_self_exn =
match Thread.setaffinity_self_exn with
| Ok f -> f
| Error err -> (* raise or provide a default implementation. *)
If your application requires that one of these operations be present then, you could just do this instead:
let setaffinity_self_exn = Or_error.ok_exn Thread.setaffinity_self_exn
val setaffinity_self_exn : (Core__.Import.Int.Set.t -> unit) Core__.Import.Or_error.t
Sets the core affinity of the currently-running thread to the set specified.
This function is implemented using
pthread_setaffinity_np(3)
, when available. See the man page for situations when this function may return an error, and therefore raise.
val getaffinity_self_exn : (unit -> Core__.Import.Int.Set.t) Core__.Import.Or_error.t
Gets the core affinity of the currently-running thread.
This function is implemented using
pthread_getaffinity_np(3)
, when available. See the man page for situations when this function may return an error, and therefore raise.
module For_testing : sig ... end