mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-28 10:30:49 +00:00
Replace ThreadingHelper wait loop with functional CyclicBarrier (#36508)
This commit is contained in:
parent
82483ed8b0
commit
843c43c97a
|
|
@ -1,17 +1,18 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'concurrent/atomic/cyclic_barrier'
|
||||||
|
|
||||||
module ThreadingHelpers
|
module ThreadingHelpers
|
||||||
def multi_threaded_execution(thread_count)
|
def multi_threaded_execution(thread_count)
|
||||||
wait_for_start = true
|
barrier = Concurrent::CyclicBarrier.new(thread_count)
|
||||||
|
|
||||||
threads = Array.new(thread_count) do
|
threads = Array.new(thread_count) do
|
||||||
Thread.new do
|
Thread.new do
|
||||||
true while wait_for_start
|
barrier.wait
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
wait_for_start = false
|
|
||||||
threads.each(&:join)
|
threads.each(&:join)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user