Eio.Executor_pool
A pool of domains for executing jobs.
An executor pool distributes jobs (functions to execute) among a pool of domain workers (threads).
Domains are reused and can execute multiple jobs concurrently. Jobs are queued up if they cannot be started immediately due to all workers being busy.
Eio.Executor_pool
is the recommended way of leveraging OCaml 5's multicore capabilities. It is built on top of the low level Eio.Domain_manager
.
Usually you will only want one pool for an entire application, so the pool is typically created when the application starts:
let () =
Eio_main.run @@ fun env ->
Switch.run @@ fun sw ->
let pool =
Eio.Executor_pool.create
~sw (Eio.Stdenv.domain_mgr env)
~domain_count:4
in
main ~pool
The pool starts its domain workers (threads) immediately upon creation.
val create : sw:Switch.t -> domain_count:int -> _ Domain_manager.t -> t
create ~sw ~domain_count dm
creates a new executor pool.
The executor pool will not block switch sw
from completing; when the switch finishes, all domain workers and running jobs are cancelled.
submit t ~weight fn
runs fn ()
using this executor pool.
The job is added to the back of the queue.
val submit_fork :
sw:Switch.t ->
t ->
weight:float ->
(unit -> 'a) ->
'a Promise.or_exn
Same as submit
but returns immediately, without blocking.