module Condition: sig
.. end
This module implements monadic
condition computations. They can be used
to write waiting code that is compatible
with duppy's tasks, i.e. Condition.wait c m
blocks
the calling computation and not the calling thread
until Condition.signal c
or Condition.broadcast c
has
been called.
type
condition
Type of a condition, used in wait
and broadcast
val create : priority:'a -> 'a Duppy.scheduler -> condition
Create a condition. Implementation-wise,
a duppy task is created that will be used to select a
waiting computation, and resume it.
Thus, priority
and s
represents, resp., the priority
and scheduler used when running calling process' computation.
val wait : condition ->
Duppy.Monad.Mutex.mutex -> (unit, 'a) Duppy.Monad.t
wait h m
is a computation that:
- Unlock mutex
m
- Wait until
Condition.signal c
or Condition.broadcast c
has been called
- Locks mutex
m
- Returns
unit
val broadcast : condition -> (unit, 'a) Duppy.Monad.t
broadcast c
is a computation that
resumes all computations waiting on c
. It should
return immediatly.
val signal : condition -> (unit, 'a) Duppy.Monad.t
signal c
is a computation that resumes one
computation waiting on c
. It should return
immediatly.