File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,25 @@ module Concurrent
55
66 # A synchronization aid that allows a set of threads to all wait for each
77 # other to reach a common barrier point.
8+ # @example
9+ # barrier = Concurrent::CyclicBarrier.new(3)
10+ # jobs = Array.new(3) { |i| -> { sleep i; p done: i } }
11+ # process = -> (i) do
12+ # # waiting to start at the same time
13+ # barrier.wait
14+ # # execute job
15+ # jobs[i].call
16+ # # wait for others to finish
17+ # barrier.wait
18+ # end
19+ # threads = 2.times.map do |i|
20+ # Thread.new(i, &process)
21+ # end
22+ #
23+ # # use main as well
24+ # process.call 2
25+ #
26+ # # here we can be sure that all jobs are processed
827 class CyclicBarrier < Synchronization ::LockableObject
928
1029 # @!visibility private
You can’t perform that action at this time.
0 commit comments