module Mutex: sig
.. end
This module implements monadic
mutex computations. They can be used
to write blocking code that is compatible
with duppy's tasks, i.e. Mutex.lock m
blocks
the calling computation and not the calling thread.
type
mutex
Type for a mutex.
val create : priority:'a -> 'a Duppy.scheduler -> mutex
create ~priority s
creates a mutex. Implementation-wise,
a duppy task is created that will be used to select a
waiting computation, lock the mutex on it and resume it.
Thus, priority
and s
represents, resp., the priority
and scheduler used when running calling process' computation.
val lock : mutex -> (unit, 'a) Duppy.Monad.t
A computation that locks a mutex
and returns unit
afterwards. Computation
will be blocked until the mutex is sucessfuly locked.
val try_lock : mutex -> (bool, 'a) Duppy.Monad.t
A computation that tries to lock a mutex.
Returns immediatly true
if the mutex was sucesfully locked
or false
otherwise.
val unlock : mutex -> (unit, 'a) Duppy.Monad.t
A computation that unlocks a mutex.
Should return immediatly.