Picos_sync.Mutex
A mutex implementation for Picos
.
âšī¸ This intentionally mimics the interface of Stdlib.Mutex
. Unlike with the standard library mutex, blocking on this mutex potentially allows an effects based scheduler to run other fibers on the thread.
đī¸ The optional checked
argument taken by most of the operations defaults to true
. When explicitly specified as ~checked:false
the mutex implementation may avoid having to obtain the current fiber, which can be expensive relative to locking or unlocking an uncontested mutex. Note that specifying ~checked:false
on an operation may prevent error checking also on a subsequent operation.
val create : ?padded:bool -> unit -> t
create ()
returns a new mutex that is initially unlocked.
val lock : ?checked:bool -> t -> unit
lock mutex
locks the mutex
.
âšī¸ If the fiber has been canceled and propagation of cancelation is allowed, this may raise the cancelation exception before locking the mutex. If ~checked:false
was specified, the cancelation exception may or may not be raised.
val try_lock : ?checked:bool -> t -> bool
try_lock mutex
locks the mutex in case the mutex is unlocked. Returns true
on success and false
in case the mutex was locked.
âšī¸ If the fiber has been canceled and propagation of cancelation is allowed, this may raise the cancelation exception before locking the mutex. If ~checked:false
was specified, the cancelation exception may or may not be raised.
val unlock : ?checked:bool -> t -> unit
unlock mutex
unlocks the mutex.
val protect : ?checked:bool -> t -> (unit -> 'a) -> 'a
protect mutex thunk
locks the mutex
, runs thunk ()
, and unlocks the mutex
after thunk ()
returns or raises.
âšī¸ If the fiber has been canceled and propagation of cancelation is allowed, this may raise the cancelation exception before locking the mutex. If ~checked:false
was specified, the cancelation exception may or may not be raised.