Class: Concurrent::CyclicBarrier

Overview

A synchronization aid that allows a set of threads to all wait for each
other to reach a common barrier point.

Examples:

barrier=Concurrent::CyclicBarrier.new(3)jobs=Array.new(3){|i|->{sleepi;pdone:i}}process=->(i)do# waiting to start at the same time
barrier.wait# execute job
jobs[i].call# wait for others to finish
barrier.waitendthreads=2.times.mapdo|i|Thread.new(i,&process)end# use main as well
process.call2# here we can be sure that all jobs are processed

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.

Blocks on the barrier until the number of waiting threads is equal to parties or until timeout is reached or reset is called If a block has been passed to the constructor, it will be executed once by the last arrived thread before releasing the others.

#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

Blocks on the barrier until the number of waiting threads is equal to
parties or until timeout is reached or reset is called
If a block has been passed to the constructor, it will be executed once by
the last arrived thread before releasing the others

Parameters:

timeout(Fixnum)(defaults to: nil)
—

the number of seconds to wait for the counter or
nil to block indefinitely

Returns:

(Boolean)
—

true if the count reaches zero else false on
timeout or on reset or if the barrier is broken