package moonpool

  1. Overview
  2. Docs
Pools of threads supported by a pool of domains

Install

Dune Dependency

Authors

Maintainers

Sources

moonpool-0.7.tbz
sha256=c4a1f974200530ab7f6014de3a369fdbb260ff454183640f32e51ba3fec51b15
sha512=865daabb96e3d60f88ecee9fc9030dad8b257fff4121b404e882d8a8d6687b737beb6e22366f52eb14e770dfab28b326853a1d3d883fa19bbd791d8450b40f8b

doc/moonpool/Moonpool/index.html

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 Background_thread : sig ... end

A simple runner with a single background thread.

Sourcemodule Runner : sig ... end

Interface for runners.

Sourcemodule Trigger : sig ... end

Triggers from picos

Sourcemodule Immediate_runner : sig ... end

Runner that runs tasks in the caller thread.

Sourcemodule Exn_bt : sig ... end

Exception with backtrace.

Sourceexception Shutdown

Exception raised when trying to run tasks on runners that have been shut down.

  • since 0.6
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 : ?fiber:Picos.Fiber.t -> 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.

  • parameter fiber

    optional initial (picos) fiber state

  • since 0.5
Sourceval run_wait_block : ?fiber:Picos.Fiber.t -> Runner.t -> (unit -> 'a) -> 'a

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

See run_async for more details.

NOTE be careful with deadlocks (see notes in Fut.wait_block about the required discipline to avoid deadlocks).

  • raises Shutdown

    if the runner was already shut down

  • since 0.6

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 get_current_runner : unit -> Runner.t option
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 Task_local_storage : sig ... end

Task-local storage.

Sourcemodule Thread_local_storage = Thread_local_storage
Sourcemodule Blocking_queue : sig ... end

A simple blocking queue.

Sourcemodule Bounded_queue : sig ... end

A blocking queue of finite size.

Atomic values.

OCaml

Innovation. Community. Security.