moonpool/src/d_pool_.mli
Simon Cruanes ed531e68e1
fix: race condition in shutdown, we need to wait for domain to quit
risk is a tight loop of `Pool.with_`, where by not waiting for the pool
to entirely shutdown (including the domains, potentially) we risk
running out of domains in the next iterations.
2023-08-13 22:24:18 -04:00

25 lines
939 B
OCaml

(** Static pool of domains.
These domains are shared between {b all} the pools in moonpool.
The rationale is that we should not have more domains than cores, so
it's easier to pre-allocate exactly that many domains, and run more flexible
thread pools on top.
*)
type domain = Domain_.t
val n_domains : unit -> int
(** Number of domains in the pool *)
val run_on : int -> (unit -> unit) -> unit
(** [run_on i f] runs [f()] on the domain with index [i].
Precondition: [0 <= i < n_domains()] *)
val decr_on : int -> domain_to_join:(Domain_.t -> unit) -> unit
(** Signal that a thread is stopping on the domain with index [i].
@param domain_to_join called with a domain if this domain shuts down
because no one is using it anymore *)
val run_on_and_wait : int -> (unit -> 'a) -> 'a
(** [run_on_and_wait i f] runs [f()] on the domain with index [i],
and blocks until the result of [f()] is returned back. *)