class Concurrent::CountDownLatch
[waiter, decrementer].each(&:join)
end
puts latch.count
latch.count_down
sleep(1)
puts latch.count
latch.count_down
sleep(1)
puts latch.count
latch.count_down
sleep(1)
decrementer = Thread.new do
end
puts (“Waiter released”)
latch.wait()
waiter = Thread.new do
latch = Concurrent::CountDownLatch.new(3)
@example Waiter and Decrementer
@!macro count_down_latch_public_api
with its work. A ‘CountDownLatch` can be used only once. Its value cannot be reset.
When the latch counter reaches zero the waiting thread is unblocked and continues
method. Each of the other threads calls `#count_down` when done with its work.
latch to the other threads then waits for the other threads by calling the `#wait`
(normally equal to the number of other threads). The initiating thread passes the
The thread that will wait creates a `CountDownLatch` and sets the initial value
A synchronization object that allows one thread to wait on multiple other threads.
@!macro count_down_latch