MoonpoolMoonpool
A pool within a bigger pool (ie the ocean). Here, we're talking about pools of Thread.t that are dispatched over several Domain.t to enable parallelism.
We provide several implementations of pools with distinct scheduling strategies, alongside some concurrency primitives such as guarding locks (Lock.t) and futures (Fut.t).
module Ws_pool : sig ... endWork-stealing thread pool.
module Fifo_pool : sig ... endA simple thread pool in FIFO order.
module Background_thread : sig ... endA simple runner with a single background thread.
module Runner : sig ... endInterface for runners.
module Immediate_runner : sig ... endRunner that runs tasks in the caller thread.
module Exn_bt : sig ... endException with backtrace.
val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.tSimilar to Thread.create, but it picks a background domain at random to run the thread. This ensures that we don't always pick the same domain to run all the various threads needed in an application (timers, event loops, etc.)
val run_async : ?ls:Task_local_storage.t -> Runner.t -> (unit -> unit) -> unitrun_async runner task schedules the task to run on the given runner. This means task() will be executed at some point in the future, possibly in another thread.
val run_wait_block : ?ls:Task_local_storage.t -> Runner.t -> (unit -> 'a) -> 'arun_wait_block runner f schedules f for later execution on the runner, 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).
Number of threads recommended to saturate the CPU. For IO pools this makes little sense (you might want more threads than this because many of them will be blocked most of the time).
spawn ~on f runs f() on the runner (a thread pool typically) and returns a future result for it. See Fut.spawn.
val spawn_on_current_runner : (unit -> 'a) -> 'a Fut.tmodule Lock : sig ... endMutex-protected resource.
module Fut : sig ... endFutures.
module Chan : sig ... endChannels.
module Task_local_storage : sig ... endTask-local storage.
module Thread_local_storage = Moonpool_private.Thread_local_storage_module Blocking_queue : sig ... endA simple blocking queue.
module Bounded_queue : sig ... endA blocking queue of finite size.
module Atomic = Moonpool_private.Atomic_Atomic values.