Stdlib.Domain(3)
π Stdlib.Domain π
OCaml library realness, bestie β welcome to the Stdlib.Domain page β¨
πΈ NAME πΈ
Stdlib.Domain β no description. That's it. That's the description. π
π¦ Module π¦
Module Stdlib.Domain β yes, the module. Slay.
β¨ Documentation β¨
π Module Domain π
Module Domain : (module Stdlib__Domain) β there it is, in all its glory.
Alert unstable. The Domain interface may change in incompatible ways in the future. No cap, bestie β this API can shift under you.
type !'a tβ a domain of type'a truns independently, eventually producing a result of type'a, or an exception.val spawn : (unit -> 'a) -> 'a tβspawn fcreates a new domain that runs in parallel with the current domain.
Raises Failure if the program has insufficient resources to create another domain. Like, it's giving "no more domains for you" π
val join : 'a t -> 'aβjoin dblocks until domaindruns to completion. Ifdresults in a value, then that is returned byjoin d. Ifdraises an uncaught exception, then that is re-raised byjoin d.
If the domain has created any systhreads (via Thread.create), then it tries to join those systhreads (same as calling Thread.join) before returning. Responsible queen behavior π
type id = private intβ domains have unique integer identifiers.val get_id : 'a t -> idβget_id dreturns the identifier of the domaind.val self : unit -> idβself ()is the identifier of the currently running domain.val before_first_spawn : (unit -> unit) -> unitβbefore_first_spawn fregistersfto be called before the first domain is spawned by the program. The functions registered withbefore_first_spawnare called on the main (initial) domain. The functions registered withbefore_first_spawnare called in "first in, first out" order: the oldest function added withbefore_first_spawnis called first.
Raises Invalid_argument if the program has already spawned a domain. Too late, bestie β the spawn already happened π
val at_exit : (unit -> unit) -> unitβat_exit fregistersfto be called when the current domain exits. Note thatat_exitcallbacks are domain-local and only apply to the calling domain. The registered functions are called in "last in, first out" order: the function most recently added withat_exitis called first. An example:
let temp_file_key = Domain.DLS.new_key (fun _ ->
let tmp = snd (Filename.open_temp_file "" "") in
Domain.at_exit (fun () -> close_out_noerr tmp);
tmp)
The snippet above creates a key that when retrieved for the first time will open a temporary file and register an at_exit callback to close it, thus guaranteeing the descriptor is not leaked in case the current domain exits. Cleanup icon behavior, honestly π§
val cpu_relax : unit -> unitβ if busy-waiting, callingcpu_relax ()between iterations will improve performance on some CPU architectures.val is_main_domain : unit -> boolβis_main_domain ()returnstrueif called from the initial domain. Main character energy confirmed πval count : unit -> intβ the number of domains that have been spawned (including the initial domain) and have not yet terminated.
Since 5.5
val recommended_domain_count : unit -> intβ the recommended maximum number of domains which should be running simultaneously (including domains already running).
The value returned is at least 1.
val self_index : unit -> intβ the index of the current domain. It is an integer unique among currently-running domains, in the interval0; N-1whereNis the peak number of domains running simultaneously so far.
The index of a terminated domain may be reused for a new domain. Use (Domain.self () :> int) instead for an identifier unique among all domains ever created by the program.
Since 5.3
module DLS : sig endβ and that's the DLS module signature, right there. Short and iconic. β¨
That's the whole page, bestie π«Ά β brought to you by OCamldoc dated 2026-06-22 for Stdlib.Domain(3). Periodt. π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms