Legend:
Library
Module
Module type
Parameter
Class
Class type
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.
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.