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_backtraceThe type for info about trapped exceptions. The context, the exception, and the backtrace.
val set_exn_trap : (exn_info -> unit) -> unitset_exn_trap his a function called whenever the runtime system traps an exception.
val pp_exn_info : Stdlib.Format.formatter -> exn_info -> unitpp_exn_info ppf iprints an unspecified representation ofionppf.
Actions
type abort= unit -> unitThe type for action's abort functions. Calling an abort function associated to an
actionfunction has the following effects and must be guaranteed by the backends:- If the
actionwasn't executed yet. It guarantees thatactionwill never be called and will be eventually gc'd. - If the
actionwas already executed, it has no effects.
- If the
Runtime actions
Signal actions
val signal_action : int -> (abort -> (int -> unit) * 'a) -> 'asignal_action s defcallsdefwith anabortfunction to get(action,v). The functionactionis scheduled for execution whenever the next signalsis received and will be called once withswhen that happens or never ifabortwas called before, seeabortfor details. The valuevis simply returned bysignal_action.
Timer actions
val timer_action : float -> (abort -> (float -> unit) * 'a) -> 'atimer_action d defcallsdefwith anabortfunction to get(action,v). The functionactionis scheduled for execution indseconds and will be called once with the actualy delay that was performed or never ifabortwas called before, seeabortfor details. The valuevis 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 -> unitset_worker_count nsets the number of workers ton.- raises Invalid_argument
if
nis negative.Note. Clients don't need to call this function explicitely, backends will automatically adjust workers once
Fut.applyis called. Also if the number of workers is set to0, a new call toFut.applymay change the worker count again.Warning. In most backends calling this function explicitely with
n > 0makes the program multithreaded..