MJIT: Do not hang after forking with threads
First, rb_mjit_fork should call rb_thread_atfork to stop threads after fork in the child process. Unfortunately, we cannot use rb_fork_ruby to prevent this kind of mistakes because MJIT needs special handling of waiting_pid and mjit_pause/resume. Second, mjit_waitpid_finished should be checked regardless of trap_interrupt. It doesn't seem like the flag is not set when SIGCHLD is handled for an MJIT child process.
This commit is contained in:
parent
c22a668580
commit
aa8a3b2358
@ -4222,6 +4222,7 @@ rb_mjit_fork(void)
|
|||||||
|
|
||||||
after_fork_ruby();
|
after_fork_ruby();
|
||||||
disable_child_handler_fork_parent(&old);
|
disable_child_handler_fork_parent(&old);
|
||||||
|
if (pid == 0) rb_thread_atfork();
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
14
thread.c
14
thread.c
@ -2321,16 +2321,16 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
|
|||||||
ret |= rb_signal_exec(th, sig);
|
ret |= rb_signal_exec(th, sig);
|
||||||
}
|
}
|
||||||
th->status = prev_status;
|
th->status = prev_status;
|
||||||
|
}
|
||||||
|
|
||||||
#if USE_MJIT
|
#if USE_MJIT
|
||||||
// Handle waitpid_signal for MJIT issued by ruby_sigchld_handler. This needs to be done
|
// Handle waitpid_signal for MJIT issued by ruby_sigchld_handler. This needs to be done
|
||||||
// outside ruby_sigchld_handler to avoid recursively relying on the SIGCHLD handler.
|
// outside ruby_sigchld_handler to avoid recursively relying on the SIGCHLD handler.
|
||||||
if (mjit_waitpid_finished) {
|
if (mjit_waitpid_finished && th == th->vm->ractor.main_thread) {
|
||||||
mjit_waitpid_finished = false;
|
mjit_waitpid_finished = false;
|
||||||
mjit_notify_waitpid(WIFEXITED(mjit_waitpid_status) ? WEXITSTATUS(mjit_waitpid_status) : -1);
|
mjit_notify_waitpid(WIFEXITED(mjit_waitpid_status) ? WEXITSTATUS(mjit_waitpid_status) : -1);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* exception from another thread */
|
/* exception from another thread */
|
||||||
if (pending_interrupt && threadptr_pending_interrupt_active_p(th)) {
|
if (pending_interrupt && threadptr_pending_interrupt_active_p(th)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user