Skip to content

Commit e9b592d

Browse files
author
Petr Chalupa
authored
Merge pull request #606 from anildigital/master
Add Countdown Latch example.
2 parents ef9bb7d + e895e25 commit e9b592d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/concurrent/atomic/count_down_latch.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ module Concurrent
7272
# with its work. A `CountDownLatch` can be used only once. Its value cannot be reset.
7373
#
7474
# @!macro count_down_latch_public_api
75+
# @example Waiter and Decrementer
76+
# latch = Concurrent::CountDownLatch.new(3)
77+
#
78+
# waiter = Thread.new do
79+
# latch.wait()
80+
# puts ("Waiter released")
81+
# end
82+
#
83+
# decrementer = Thread.new do
84+
# sleep(1)
85+
# latch.count_down
86+
# puts latch.count
87+
#
88+
# sleep(1)
89+
# latch.count_down
90+
# puts latch.count
91+
#
92+
# sleep(1)
93+
# latch.count_down
94+
# puts latch.count
95+
# end
96+
#
97+
# [waiter, decrementer].each(&:join)
7598
class CountDownLatch < CountDownLatchImplementation
7699
end
77100
end

0 commit comments

Comments
 (0)