package moonpool

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

Install

Dune Dependency

Authors

Maintainers

Sources

moonpool-0.8.tbz
sha256=2c10792726b1c2e4987f0f2acca5c5c221ea5cc0a2b4c75ad4fd2709e32aab6f
sha512=801c399ae9b72dd5f84624cdee9bcbb56c5ed9c371001e00176e685686234b4135d69e48877412b25a5127ad59b729000d5422dad0c90e2ded2744b974dddeca

doc/moonpool.sync/Moonpool_sync/Lock/index.html

Module Moonpool_sync.LockSource

Mutex-protected resource.

This lock is a synchronous concurrency primitive, as a thin wrapper around Mutex that encourages proper management of the critical section in RAII style:

  let (let@) = (@@)


  …
  let compute_foo =
    (* enter critical section *)
    let@ x = Lock.with_ protected_resource in
    use_x;
    return_foo ()
    (* exit critical section *)
  in
  …

This lock is based on Picos_sync.Mutex so it is await-safe.

  • since 0.7
Sourcetype 'a t

A value protected by a cooperative mutex

Sourceval create : 'a -> 'a t

Create a new protected value.

Sourceval with_ : 'a t -> ('a -> 'b) -> 'b

with_ l f runs f x where x is the value protected with the lock l, in a critical section. If f x fails, with_lock l f fails too but the lock is released.

Sourceval update : 'a t -> ('a -> 'a) -> unit

update l f replaces the content x of l with f x, while protected by the mutex.

Sourceval update_map : 'a t -> ('a -> 'a * 'b) -> 'b

update_map l f computes x', y = f (get l), then puts x' in l and returns y, while protected by the mutex.

Underlying mutex.

Sourceval get : 'a t -> 'a

Atomically get the value in the lock. The value that is returned isn't protected!

Sourceval set : 'a t -> 'a -> unit

Atomically set the value.

NOTE caution: using get and set as if this were a ref is an anti pattern and will not protect data against some race conditions.

OCaml

Innovation. Community. Security.