Class: Concurrent::CyclicBarrier
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Synchronization::LockableObject
|
Defined in: | lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb |
Overview
A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.
Class Method Summary
-
.new(parties) { ... } ⇒ CyclicBarrier
constructor
Create a new
CyclicBarrier
that waits for #parties threads.
Instance Attribute Summary
- #broken? ⇒ Boolean readonly
Instance Method Summary
- #number_waiting ⇒ Fixnum
- #parties ⇒ Fixnum
-
#reset ⇒ nil
resets the barrier to its initial state 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 If the barrier is broken, this method restores it to the original state.
- #wait(timeout = nil) ⇒ Boolean
Synchronization::LockableObject
- Inherited
Constructor Details
.new(parties) { ... } ⇒ CyclicBarrier
Create a new CyclicBarrier
that waits for #parties threads
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 40
def initialize(parties, &block) Utility::NativeInteger.ensure_integer_and_bounds parties Utility::NativeInteger.ensure_positive_and_no_zero parties super(&nil) synchronize { ns_initialize parties, &block } end
Instance Attribute Details
#broken? ⇒ Boolean
(readonly)
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 105
def broken? synchronize { @generation.status != :waiting } end
Instance Method Details
#number_waiting ⇒ Fixnum
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 54
def number_waiting synchronize { @number_waiting } end
#parties ⇒ Fixnum
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 49
def parties synchronize { @parties } end
#reset ⇒ nil
resets the barrier to its initial state 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 If the barrier is broken, this method restores it to the original state
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 95
def reset synchronize { ns_generation_done @generation, :reset } end
#wait(timeout = nil) ⇒ Boolean
# File 'lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb', line 66
def wait(timeout = nil) synchronize do return false unless @generation.status == :waiting @number_waiting += 1 if @number_waiting == @parties @action.call if @action ns_generation_done @generation, :fulfilled true else generation = @generation if ns_wait_until(timeout) { generation.status != :waiting } generation.status == :fulfilled else ns_generation_done generation, :broken, false false end end end end