Skip to content

Commit bf21734

Browse files
committed
added CyclicBarrier stub
1 parent 26b08c2 commit bf21734

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module Concurrent
2+
3+
class CyclicBarrier
4+
5+
# Create a new `CyclicBarrier` that waits for `parties` threads
6+
#
7+
# @param [Fixnum] parties the number of parties
8+
# @yield an optional block that will be executed that will be executed after the last thread arrives and before the others are released
9+
#
10+
# @raise [ArgumentError] if `parties` is not an integer or is less than zero
11+
def initialize(parties)
12+
end
13+
14+
# @return [Fixnum] the number of threads needed to pass the barrier
15+
def parties
16+
end
17+
18+
# @return [Fixnum] the number of threads currently waiting on the barrier
19+
def number_waiting
20+
end
21+
22+
# Blocks on the barrier until the number of waiting threads is equal to `parties` or until `timeout` is reached or `reset` is called
23+
# @param [Fixnum] timeout the number of seconds to wait for the counter or `nil` to block indefinitely
24+
# @return [Boolean] `true` if the `count` reaches zero else false on `timeout` or on `reset`
25+
def wait(timeout = nil)
26+
end
27+
28+
# resets the barrier to its initial state
29+
# If there is at least one waiting thread, it will be woken up, the `wait` method will return false and the barrier will be broken
30+
#
31+
# @return [nil]
32+
def reset
33+
end
34+
35+
# A barrier can be broken when:
36+
# - a thread called the `reset` method while at least one thread was waiting
37+
# - at least one thread timed out on `wait` method
38+
#
39+
# A broken barrier cannot be restored and it should not be reused: it's safer to create a new one
40+
# @return [Boolean] true if the barrier is broken otherwise false
41+
def broken?
42+
end
43+
44+
end
45+
end

lib/concurrent/atomics.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'concurrent/atomic/condition'
44
require 'concurrent/atomic/copy_on_notify_observer_set'
55
require 'concurrent/atomic/copy_on_write_observer_set'
6+
require 'concurrent/atomic/cyclic_barrier'
67
require 'concurrent/atomic/count_down_latch'
78
require 'concurrent/atomic/event'
89
require 'concurrent/atomic/thread_local_var'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'spec_helper'
2+
3+
module Concurrent
4+
5+
describe CyclicBarrier do
6+
7+
end
8+
9+
10+
end

0 commit comments

Comments
 (0)