package picos_aux

  1. Overview
  2. Docs
Auxiliary libraries for Picos

Install

Dune Dependency

Authors

Maintainers

Sources

picos-0.6.0.tbz
sha256=3f5a08199cf65c2dae2f7d68f3877178f1da8eabf5376e15114e5a8958087dfa
sha512=ad24910c47ce614268c4268874bb918da7f8b5f03b3ad706bbf30323635262e94ddab6be24eaebbca706bfa82c0a517d4272b396459e020c185942125c9bdb7b

doc/picos_aux.mpmcq/Picos_aux_mpmcq/index.html

Module Picos_aux_mpmcqSource

Lock-free multi-producer, multi-consumer queue.

🏎️ This data structure is optimized for use as a building block of the ready queue of a (mostly) fair (i.e. mostly FIFO) multi-threaded scheduler. For example, one could use a queue per thread, to reduce contention, and have threads attempt to pop fibers from the queues of other threads when their local queues are empty. It is also possible to use only a single shared queue, but that will result in very high contention as this queue is not relaxed.

API

Sourcetype !'a t

A multi-producer, multi-consumer queue.

Sourceval create : ?padded:bool -> unit -> 'a t

create () returns a new empty multi-producer, multi-consumer queue.

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

push queue value adds the value to the tail of the queue.

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

push_head queue value adds the value to the head of the queue.

Sourceexception Empty

Raised by pop_exn in case it finds the queue empty.

Sourceval pop_exn : 'a t -> 'a

pop_exn queue tries to remove the value at the head of the queue. Returns the removed value or raises Empty in case the queue was empty.

  • raises Empty

    in case the queue was empty.

Sourceval length : 'a t -> int

length queue returns the length or the number of values in the queue.

Sourceval is_empty : 'a t -> bool

is_empty queue is equivalent to length queue = 0.

Examples

An example top-level session:

  # let q : int Picos_aux_mpmcq.t =
      Picos_aux_mpmcq.create ()
  val q : int Picos_aux_mpmcq.t = <abstr>

  # Picos_aux_mpmcq.push q 42
  - : unit = ()

  # Picos_aux_mpmcq.push_head q 76
  - : unit = ()

  # Picos_aux_mpmcq.length q
  - : int = 2

  # Picos_aux_mpmcq.push q 101
  - : unit = ()

  # Picos_aux_mpmcq.pop_exn q
  - : int = 76

  # Picos_aux_mpmcq.pop_exn q
  - : int = 42

  # Picos_aux_mpmcq.pop_exn q
  - : int = 101

  # Picos_aux_mpmcq.pop_exn q
  Exception: Picos_aux_mpmcq.Empty.
OCaml

Innovation. Community. Security.

On This Page
  1. API
  2. Examples