class

Concurrent::CountDownLatch

Inherits Reference / Object

Allows fibers to wait until a series of operations performed in other fibers complete.

This class has additional capabilities not found in java or other implementations:

  • wait_count may be set at initialization or if not provided to initialize() any time after (only once between resets).
  • Reset is allowed after the latch is released. The object may be reused but is not a cyclic barrier.

A single atomic counter is used. This implementation is 30-40% faster than using a Mutex or Channel::Buffered on Crystal 0.29.0-dev and likely to be faster still when channels are thread safe.

Constructors

new(saved_wait_count : Int32 = 0)
Source

Instance methods

count

Current count.

Source
count_down
Source
count_up(n = 1) : Nil
Source
error(ex : Exception) : Nil

Use instead of count_down. Stores the first error and raises it when #wait is called.

Source
reset

Only call reset after latch is released or after initialize. Undefined behavior if called between use of count_down and release.

Source
wait

Wait until count_down has been called wait_count times. TODO: timeout

Source
wait_count
Source
wait_count=(wait_count : Int32) : Int32

Must be set exactly once and only if not supplied to #initialize

Source

Nested types