Re-initialize vm->ractor.sched.lock after fork

Previously under certain conditions it was possible to encounter a
deadlock in the forked child process if ractor.sched.lock was held.

Co-authored-by: Nathan Froyd <froydnj@gmail.com>
This commit is contained in:
John Hawthorn 2024-08-08 02:10:15 -07:00
Родитель 908305a297
Коммит 87a85550ed
2 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -75,3 +75,25 @@ assert_equal '[1, 2]', %q{
end
}, '[ruby-dev:44005] [Ruby 1.9 - Bug #4950]'
assert_equal 'ok', %q{
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Thread.new do
loop { sleep 0.0001 }
end
10.times do
pid = fork{ exit!(0) }
deadline = now + 1
until Process.waitpid(pid, Process::WNOHANG)
if now > deadline
Process.kill(:KILL, pid)
raise "failed"
end
sleep 0.001
end
rescue NotImplementedError
end
:ok
}, '[Bug #20670]'

Просмотреть файл

@ -1556,6 +1556,7 @@ thread_sched_atfork(struct rb_thread_sched *sched)
}
vm->ractor.sched.running_cnt = 0;
rb_native_mutex_initialize(&vm->ractor.sched.lock);
// rb_native_cond_destroy(&vm->ractor.sched.cond);
rb_native_cond_initialize(&vm->ractor.sched.cond);
rb_native_cond_initialize(&vm->ractor.sched.barrier_complete_cond);