Module Await_sync.Countdown_latch

A poisonable one-shot countdown latch.

type t

A Countdown_latch.t is a synchronization aid that allows one or more threads to wait until a number of operations being performed in other threads complete.

A countdown latch is initialized with a count. The await method blocks until a call to decr decrements the count to zero, after which all waiting threads are released. A countdown latch is one-shot -- the count cannot be changed after it reaches zero. If you need a version that resets the count, consider using a Barrier instead, though note that with a barrier the only operation available is waiting - it is not possible to decrement without blocking.

val sexp_of_t : t -> Sexplib0.Sexp.t
val max_count : Base.int @@ portable

max_count is the maximum allowed count for a countdown latch.

val create : ?padded:Base.bool @ local -> (Base.int -> t) @ local @@ portable

create n returns a new countdown latch with its count initialized to n.

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

val count : t @ local -> Base.int @@ portable

count t returns the current count of the countdown latch t.

val poison : t @ local -> Base.unit @@ portable

poison t marks the countdown latch as poisoned. Concurrent and subsequent calls to await, await_or_cancel, and incr will raise the Poisoned exception.

val is_poisoned : t @ local -> Base.bool @@ portable

is_poisoned t determines whether the countdown latch has been poisoned.

val incr : t @ local -> Base.unit @@ portable

incr t increments the count of the countdown latch t.

The count is not logically modified after it has reached zero.

  • raises Poisoned

    if the latch has been poisoned.

val decr : t @ local -> Base.unit @@ portable

decr t decrements the count of the countdown latch t, releasing all waiting threads if the count reaches zero.

The count is not logically modified after it has reached zero.

val await : Await_kernel.Await.t @ local -> (t @ local -> Base.unit) @ local @@ portable

await w t suspends the caller until the latch t is decremented to zero.

  • raises Poisoned

    if the latch has been poisoned.

  • raises Terminated

    if w is terminated before the latch reaches zero.

val await_or_cancel : Await_kernel.Await.t @ local -> (Await_kernel.Cancellation.t @ local -> (t @ local -> Base.unit Await_kernel.Or_canceled.t) @ local) @ local @@ portable

await_or_cancel w c t is Completed () if c is not cancelled or Canceled otherwise

  • raises Poisoned

    if the latch has been poisoned.

  • raises Terminated

    if w is terminated, even if c is canceled.