Skip to content

Commit 1333749

Browse files
committed
Wait for threads to start up before starting
1 parent 2364e6a commit 1333749

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/overcommit/hook_runner.rb

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(config, logger, context, printer)
1616
@lock = Mutex.new
1717
@resource = ConditionVariable.new
1818
@main = ConditionVariable.new
19+
@hooks_ready = 0
1920
@slots_available = @config.concurrency
2021
@hooks_finished = 0
2122
end
@@ -58,6 +59,7 @@ def run_hooks
5859
@printer.start_run
5960

6061
@threads = @hooks.map { |hook| Thread.new(hook, &method(:run_hook)) }
62+
wait_for_workers_to_start
6163

6264
begin
6365
InterruptHandler.disable_until_finished_or_interrupted do
@@ -81,6 +83,14 @@ def run_hooks
8183
end
8284
end
8385

86+
def wait_for_workers_to_start
87+
while @hooks_ready < @threads.size
88+
@lock.synchronize do
89+
@main.wait(@lock)
90+
end
91+
end
92+
end
93+
8494
def start_and_wait_for_workers
8595
@resource.signal
8696

@@ -91,6 +101,8 @@ def start_and_wait_for_workers
91101

92102
def wait_for_slot(hook)
93103
@lock.synchronize do
104+
@main.signal # Tell the main thread that we're ready to run
105+
@hooks_ready += 1
94106
slots_needed = hook.parallelize? ? 1 : @config.concurrency
95107

96108
loop do

0 commit comments

Comments
 (0)