Module Kcas_data.Mvar

Synchronizing variable.

A synchronizing variable is essentially equivalent to a 'a option Loc.t with blocking semantics on both take and put.

NOTE: The current implementation is not guaranteed to be fair or scalable. In other words, when multiple producers block on put or multiple consumers block on take the operations are not queued and it is possible for a particular producer or consumer to starve.

Common interface

type !'a t

The type of a synchronizing variable that may contain a value of type 'a.

val create : 'a option -> 'a t

create x_opt returns a new synchronizing variable that will either be empty when x_opt is None or full when x_opt is Some x.

Compositional interface

module Xt : sig ... end

Explicit transaction passing on synchronizing variables.

Non-compositional interface

val is_empty : 'a t -> bool

is_empty mv determines whether the synchronizing variable mv contains a value or not.

val put : ?timeoutf:float -> 'a t -> 'a -> unit

put mv x fills the synchronizing variable mv with the value v or blocks until the variable becomes empty.

val try_put : 'a t -> 'a -> bool

try_put mv x tries to fill the synchronizing variable mv with the value v and returns true on success or false in case the variable is full.

val take : ?timeoutf:float -> 'a t -> 'a

take mv removes and returns the current value of the synchronizing variable mv or blocks waiting until the variable is filled.

val take_opt : 'a t -> 'a option

take_opt mv removes and returns the current value of the synchronizing variable mv or returns None in case the variable is empty.

val peek : ?timeoutf:float -> 'a t -> 'a

peek mv returns the current value of the synchronizing variable mv or blocks waiting until the variable is filled.

val peek_opt : 'a t -> 'a option

peek_opt mv returns the current value of the synchronizing variable mv or returns None in case the variable is empty.