Skip to content

Commit a444551

Browse files
committed
fixed CyclicBarrier#wait return value on reset
1 parent 72a5035 commit a444551

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/concurrent/atomic/cyclic_barrier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def number_waiting
3636
# Blocks on the barrier until the number of waiting threads is equal to `parties` or until `timeout` is reached or `reset` is called
3737
# If a block has been passed to the constructor, it will be executed once by the last arrived thread before releasing the others
3838
# @param [Fixnum] timeout the number of seconds to wait for the counter or `nil` to block indefinitely
39-
# @return [Boolean] `true` if the `count` reaches zero else false on `timeout` or on `reset` or on broken event
39+
# @return [Boolean] `true` if the `count` reaches zero else false on `timeout` or on `reset` or if the barrier is broken
4040
def wait(timeout = nil)
4141
@mutex.synchronize do
4242

@@ -60,7 +60,7 @@ def wait(timeout = nil)
6060
end
6161

6262
if remaining.woken_up?
63-
return true
63+
return generation.status == :fulfilled
6464
else
6565
generation.status = :broken
6666
@condition.broadcast

spec/concurrent/atomic/cyclic_barrier_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ module Concurrent
120120
parties.times { Thread.new { barrier.wait; latch.count_down } }
121121
latch.wait(0.1).should be_true
122122
end
123+
124+
it 'return false if barrier has been reset' do
125+
latch = CountDownLatch.new(1)
126+
127+
Thread.new { latch.count_down if barrier.wait == false }
128+
sleep(0.1)
129+
barrier.reset
130+
latch.wait(0.1).should be_true
131+
end
123132
end
124133

125134
context 'with timeout' do

0 commit comments

Comments
 (0)