class Concurrent::CountDownLatch
- Concurrent::CountDownLatch
- Reference
- Object
Overview
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.
Defined in:
concurrent/count_down_latch.crConstructors
Instance Method Summary
-
#count
Current count.
- #count_down : Nil
- #count_up(n = 1) : Nil
-
#error(ex : Exception) : Nil
Use instead of count_down.
-
#reset
Only call reset after latch is released or after initialize.
-
#wait : self
Wait until count_down has been called wait_count times.
- #wait_count : Int32
-
#wait_count=(wait_count : Int32) : Int32
Must be set exactly once and only if not supplied to #initialize
Constructor Detail
Instance Method Detail
Use instead of count_down. Stores the first error and raises it when #wait is called.
Only call reset after latch is released or after initialize. Undefined behavior if called between use of count_down and release.
Must be set exactly once and only if not supplied to #initialize