Legend:
Library
Module
Module type
Parameter
Class
Class type
A simple thread pool in FIFO order.
FIFO: first-in, first-out. Basically tasks are put into a queue, and worker threads pull them out of the queue at the other end.
Since this uses a single blocking queue to manage tasks, it's very simple and reliable. The number of worker threads is fixed, but they are spread over several domains to enable parallelism.
This can be useful for latency-sensitive applications (e.g. as a pool of workers for network servers). Work-stealing pools might have higher throughput but they're very unfair to some tasks; by contrast, here, older tasks have priority over younger tasks.
If a runner is no longer needed, shutdown can be used to signal all worker threads in it to stop (after they finish their work), and wait for them to stop.
The threads are distributed across a fixed domain pool (whose size is determined by Domain.recommended_domain_count on OCaml 5, and simple the single runtime on OCaml 4).
if the runner was shut down before run_async was called.
val run_wait_block : ?fiber:fiber->t->(unit ->'a)->'a
run_wait_block pool f schedules f for later execution on the pool, like run_async. It then blocks the current thread until f() is done executing, and returns its result. If f() raises an exception, then run_wait_block pool f will raise it as well.
NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).
called at the beginning of each new thread in the pool.
parametermin
minimum size of the pool. See Pool.create_args. The default is Domain.recommended_domain_count(), ie one worker per CPU core. On OCaml 4 the default is 4 (since there is only one domain).
parameteron_exit_thread
called at the end of each worker thread in the pool.
parameteraround_task
a pair of before, after functions ran around each task. See Pool.create_args.
with_ () f calls f pool, where pool is obtained via create. When f pool returns or fails, pool is shutdown and its resources are released. Most parameters are the same as in create.