Module Await_sync.Stack

A multi-producer, multi-consumer concurrent stack.

type !'a t

A simple, list-based multi-producer multi-consumer stack which provides both lock-free and blocking operations.

include sig ... end
val sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val create : ?padded:Base.bool @ local -> (Base.unit -> 'a t) @ local @@ portable

create () creates and returns a new empty stack.

The optional padded argument specifies whether to pad the data structure to avoid false sharing. See Atomic.make for a longer explanation.

val push : 'a t @ local -> ('a @ portable contended -> Base.unit) @ local @@ portable

push t a enqueues a at the head of t.

val pop : Await_kernel.Await.t @ local -> ('a t @ local -> 'a @ portable contended) @ local @@ portable

pop await t removes and returns the most-recently-pushed value from the head of t, blocking using await if t is empty.

val pop_or_cancel : Await_kernel.Await.t @ local -> (Await_kernel.Cancellation.t @ local -> ('a t @ local -> 'a Await_kernel.Or_canceled.t @ portable contended) @ local) @ local @@ portable

pop_or_cancel await c t is Completed (pop await t) if c is not cancelled, otherwise it is Canceled.

  • raises Terminated

    if w is terminated, even if c is canceled.

val pop_nonblocking : 'a t @ local -> 'a Base.or_null @ portable contended @@ portable

pop_nonblocking t removes and returns the most-recently-pushed value from the head of t, or returns Null if the stack is empty.

val drain : 'a t @ local -> 'a Base.list @ portable contended @@ portable

drain t removes and returns all items from t without blocking, returning a list with the most-recently-enqueued item first.

module For_testing : sig ... end