Module Fut.Runtime
Runtime system configuration and interaction.
Exception trap
See also the section about exceptions.
type exn_ctx
=[
|
`Queue of string
|
`Future
|
`Finalizer
|
`Backend
|
`Fd_action
|
`Timer_action
|
`Signal_action
|
`Runtime_action
|
`Exn_trap
]
The type for exception contexts.
type exn_info
= exn_ctx * exn * Stdlib.Printexc.raw_backtrace
The type for info about trapped exceptions. The context, the exception, and the backtrace.
val set_exn_trap : (exn_info -> unit) -> unit
set_exn_trap h
is a function called whenever the runtime system traps an exception.
val pp_exn_info : Stdlib.Format.formatter -> exn_info -> unit
pp_exn_info ppf i
prints an unspecified representation ofi
onppf
.
Actions
type abort
= unit -> unit
The type for action's abort functions. Calling an abort function associated to an
action
function has the following effects and must be guaranteed by the backends:- If the
action
wasn't executed yet. It guarantees thataction
will never be called and will be eventually gc'd. - If the
action
was already executed, it has no effects.
- If the
Runtime actions
Signal actions
val signal_action : int -> (abort -> (int -> unit) * 'a) -> 'a
signal_action s def
callsdef
with anabort
function to get(action,v)
. The functionaction
is scheduled for execution whenever the next signals
is received and will be called once withs
when that happens or never ifabort
was called before, seeabort
for details. The valuev
is simply returned bysignal_action
.
Timer actions
val timer_action : float -> (abort -> (float -> unit) * 'a) -> 'a
timer_action d def
callsdef
with anabort
function to get(action,v)
. The functionaction
is scheduled for execution ind
seconds and will be called once with the actualy delay that was performed or never ifabort
was called before, seeabort
for details. The valuev
is simply returned bytimer_action
.
File descriptor actions and closing
Workers
Note. Most of the time a worker maps to a system thread, but the exact semantics is backend dependent. Workers are typically used to determine the future of futures queues.
Threads. If a backend uses threads it guarantees that the number of threads is 0
before any call is made to Fut.apply
or set_worker_count
. This allows to fork TODO we need more to be able to fork.
val set_worker_count : int -> unit
set_worker_count n
sets the number of workers ton
.- raises Invalid_argument
if
n
is negative.Note. Clients don't need to call this function explicitely, backends will automatically adjust workers once
Fut.apply
is called. Also if the number of workers is set to0
, a new call toFut.apply
may change the worker count again.Warning. In most backends calling this function explicitely with
n > 0
makes the program multithreaded..