class Concurrent::CountDownLatch

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:

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(saved_wait_count = 0) #

[View source]

Instance Method Detail

def count #

Current count.


[View source]
def count_down : Nil #

[View source]
def count_up(n = 1) : Nil #

[View source]
def error(ex : Exception) : Nil #

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


[View source]
def reset #

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


[View source]
def wait : self #

Wait until count_down has been called wait_count times.

TODO timeout


[View source]
def wait_count : Int32 #

[View source]
def wait_count=(wait_count : Int32) : Int32 #

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


[View source]