You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
353 B
18 lines
353 B
# frozen_string_literal: true |
|
|
|
require 'concurrent/atomic/cyclic_barrier' |
|
|
|
module ThreadingHelpers |
|
def multi_threaded_execution(thread_count) |
|
barrier = Concurrent::CyclicBarrier.new(thread_count) |
|
|
|
threads = Array.new(thread_count) do |
|
Thread.new do |
|
barrier.wait |
|
yield |
|
end |
|
end |
|
|
|
threads.each(&:join) |
|
end |
|
end
|
|
|