Module Stdlib.Domain

type 'a t

A domain of type 'a t runs independently, eventually producing a result of type 'a, or an exception

val spawn : (unit -> 'a) -> 'a t

spawn f creates a new domain that runs in parallel with the current domain.

val join : 'a t -> 'a

join d blocks until domain d runs to completion. If d results in a value, then that is returned by join d. If d raises an uncaught exception, then that is thrown by join d. Domains may only be joined once: subsequent uses of join d raise Invalid_argument.

type id = private int

Domains have unique integer identifiers

val get_id : 'a t -> id

get_id d returns the identifier of the domain d

val self : unit -> id

self () is the identifier of the currently running domain

val at_first_spawn : (unit -> unit) -> unit

Register the given function to be called before the first domain is spawned.

  • raises Invalid_argument

    if the first domain has already been spawned.

val at_exit : (unit -> unit) -> unit

Register the given function to be called at when a domain exits. This function is also registered with Stdlib.at_exit. If the registered function raises an exception, the exceptions are ignored.

val at_startup : (unit -> unit) -> unit

Register the given function to be called when a domain starts. This function is called before the callback specified to spawn f is executed.

val cpu_relax : unit -> unit

If busy-waiting, calling cpu_relax () between iterations will improve performance on some CPU architectures

val set_name : string -> unit

set_name s set the domain's thread name to s. s should not be longer than 15 characters. If s is longer than 15 characters, raise Invalid_argument.

val is_main_domain : unit -> bool

is_main_domain () returns true if called from the initial domain.

module DLS : sig ... end

Domain-local Storage