package moonpool

  1. Overview
  2. Docs

Module MoonpoolSource

Moonpool

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).

Sourcemodule Ws_pool : sig ... end

Work-stealing thread pool.

Sourcemodule Fifo_pool : sig ... end

A simple thread pool in FIFO order.

Sourcemodule Runner : sig ... end

Interface for runners.

Sourcemodule Immediate_runner : sig ... end

Runner that runs tasks immediately in the caller thread.

Sourcemodule Pool = Fifo_pool

Default pool. Please explicitly pick an implementation instead.

Sourceval start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.t

Similar 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.)

Sourceval run_async : Runner.t -> (unit -> unit) -> unit

run_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.

  • since 0.5

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).

  • since 0.5
Sourceval spawn : on:Runner.t -> (unit -> 'a) -> 'a Fut.t

spawn ~on f runs f() on the runner (a thread pool typically) and returns a future result for it. See Fut.spawn.

  • since 0.5
Sourceval spawn_on_current_runner : (unit -> 'a) -> 'a Fut.t
Sourceval await : 'a Fut.t -> 'a

Await a future. See Await. Only on OCaml >= 5.0.

  • since 0.5
Sourcemodule Lock : sig ... end

Mutex-protected resource.

Sourcemodule Fut : sig ... end

Futures.

Sourcemodule Chan : sig ... end

Channels.

Sourcemodule Fork_join : sig ... end

Fork-join primitives.

Sourcemodule Thread_local_storage : sig ... end

Thread local storage

Sourcemodule Blocking_queue : sig ... end

A simple blocking queue.

Sourcemodule Bounded_queue : sig ... end

A blocking queue of finite size.

Sourcemodule Atomic : sig ... end

Atomic values.