jon.recoil.org

Module Private.Thread_pool

A pool of systhreads, to avoid the overhead of creating a new thread for each operation.

type t

create ~sleep_q is a new thread pool.

sleep_q is used to register a clean-up task to finish idle threads.

val run : Eio_unix.Private.Thread_pool.t -> (unit -> 'a) -> 'a

run t fn runs fn () and then marks t as closed, releasing all idle threads.

val submit : Eio_unix.Private.Thread_pool.t -> ctx:Eio.Private.Fiber_context.t -> enqueue:(('a, Eio.Exn.with_bt) Stdlib.result -> unit) -> (unit -> 'a) -> unit

submit t ~ctx ~enqueue fn starts running fn in a sys-thread, which uses enqueue to return the result.

If ctx is already cancelled then the error is passed to enqueue immediately. Systhreads do not respond to cancellation once running.

type Stdlib.Effect.t +=
  1. | Run_in_systhread : (unit -> 'a) -> (('a, Eio.Exn.with_bt) Stdlib.result * Eio_unix.Private.Thread_pool.t) Stdlib.Effect.t
val run_in_systhread : ?label:string -> (unit -> 'a) -> 'a