package kcas_data

  1. Overview
  2. Docs

Module Kcas_data.MvarSource

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

Sourcetype !'a t

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

Sourceval 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

Sourcemodule Xt : sig ... end

Explicit transaction passing on synchronizing variables.

Non-compositional interface

Sourceval is_empty : 'a t -> bool

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

Sourceval put : 'a t -> 'a -> unit

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

Sourceval 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.

Sourceval take : 'a t -> 'a

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

Sourceval 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.

Sourceval peek : 'a t -> 'a

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

Sourceval 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.