From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id DC7321F597; Wed, 25 Jul 2018 00:19:47 +0000 (UTC) Date: Wed, 25 Jul 2018 00:19:47 +0000 From: Eric Wong To: spew@80x24.org Subject: [PATCH 2/1] thread.c (rb_threadptr_execute_interrupts): drain pipe and handle SIGCHLD Message-ID: <20180725001947.77uutfvtkn3cq235@whir> References: <20180724234104.19419-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180724234104.19419-1-e@80x24.org> List-Id: ruby_sigchld_handler always needs to run; even when SIGCHLD is ignored. test/ruby/test_signal.rb::test_sigchld_ignore occasionally got stuck from this (the bigger question is why did it not ALWAYS get stuck without this patch...). --- thread.c | 9 +++++---- thread_pthread.c | 7 +++++++ thread_win32.c | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/thread.c b/thread.c index af66d64dca..9b3ac83f8c 100644 --- a/thread.c +++ b/thread.c @@ -2138,6 +2138,9 @@ threadptr_get_interrupts(rb_thread_t *th) return interrupt & (rb_atomic_t)~ec->interrupt_mask; } +/* signal.c */ +void ruby_sigchld_handler(rb_vm_t *); + MJIT_FUNC_EXPORTED void rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) { @@ -2165,6 +2168,8 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) if (trap_interrupt && (th == th->vm->main_thread)) { enum rb_thread_status prev_status = th->status; th->status = THREAD_RUNNABLE; + rb_sigwait_fd_drain(); + ruby_sigchld_handler(th->vm); while ((sig = rb_get_next_signal()) != 0) { rb_signal_exec(th, sig); } @@ -4202,10 +4207,6 @@ rb_gc_set_stack_end(VALUE **stack_end_p) } #endif - -/* signal.c */ -void ruby_sigchld_handler(rb_vm_t *); - /* * */ diff --git a/thread_pthread.c b/thread_pthread.c index efd792fccc..402cd12fd0 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1767,4 +1767,11 @@ native_sleep(rb_thread_t *th, struct timespec *timeout_rel) } } +static void +rb_sigwait_fd_drain(void) +{ + if (timer_thread_pipe.normal[0] >= 0) { + consume_communication_pipe(timer_thread_pipe.normal[0]); + } +} #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ diff --git a/thread_win32.c b/thread_win32.c index 7f78601f68..e21dca807e 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -822,4 +822,9 @@ rb_thread_create_mjit_thread(void (*worker_func)(void)) return TRUE; } +static void +rb_sigwait_fd_drain(void) +{ + /* noop */ +} #endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */ -- EW