package miou

  1. Overview
  2. Docs

Due to our scheduler, we must re-implement few things like "Condition" to be able to wait and signal (or broadcast) our tasks. The suspension of a task must always be notified to Miou. It is possible to use real Condition.t with Miou - however, some mechanisms such as cancellation will not work.

This module reimplements the Condition with Miou. The behaviour remains the same, except that the user can Miou.cancel a task while it is waiting for a signal/broadcast.

type t

The type of condition variables.

val make : ?mutex:Mutex.t -> unit -> t

make ?mutex () creates and return a new condition variable. The mutex is used in the until function to observe the validity of a predicate. It is recommended that any change of state of this predicate should be protected by this same mutex.

val wait : t -> unit

wait t suspends the current task on the condition variable t. The task can later be woken up after the condition variable t has been signaled via signal or broadcast. wait does not lock the internal mutex passed as a parameter to the make function. Spurious wakeups does not happen - only signal or broadcast can wakeup the task.

NOTE: A signal can be sent before the other task waits. In this case (and according to our documentation), if you only intend to send one signal, the other task will still be suspended.

val until : predicate:(unit -> bool) -> fn:(unit -> 'a) -> t -> 'a

until ~predicate ~fn t waits as long as predicate is true. Then, we execute fn as soon as the process has unblocked. The execution of predicate and fn is protected by the mutex internal to condition t (passed as a parameter to the make function).

NOTE: The function fn should recheck the predicate. Indeed, in parallel programming (see Miou.call), it can happen that a domain re-invalidates the expected predicate before fn is executed.

val signal : t -> unit

signal t wakes up one of the tasks waiting on the condition variable t, if there is one. if there is none, this call has no effect.

val broadcast : t -> unit

broadcast t wakes up all tasks waiting on the condition variable t, if there is one. If there is none, this call has no effect.

OCaml

Innovation. Community. Security.