From: Eric Wong Date: 2015-07-17T10:15:30+00:00 Subject: [ruby-core:70012] Re: [Ruby trunk - Bug #11362] [Open] [PATCH] ensure Process.kill(:STOP, $$) is resumable Alternative patch, but I relying on sched_yield() may be unreliable. Anyways, both patches are hacky; but so is the expected behavior of immediate delivery when a process signals itself... --- a/thread.c +++ b/thread.c @@ -5262,6 +5262,11 @@ ruby_kill(rb_pid_t pid, int sig) { int err; rb_thread_t *th = GET_THREAD(); +#ifdef SIGSTOP + int sigstop = sig == SIGSTOP; +#else + int sigstop = 0; +#endif /* * When target pid is self, many caller assume signal will be @@ -5271,7 +5276,16 @@ ruby_kill(rb_pid_t pid, int sig) GVL_UNLOCK_BEGIN(); native_mutex_lock(&th->interrupt_lock); err = kill(pid, sig); - native_cond_wait(&th->interrupt_cond, &th->interrupt_lock); + if (sigstop) { + /* + * best effort to try to receive SIGSTOP ASAP, + * maybe we need to yield several more times. + */ + native_thread_yield(); + } + else { /* sig is SIGKILL, SIGSEGV, or SIGBUS: wait to die */ + native_cond_wait(&th->interrupt_cond, &th->interrupt_lock); + } native_mutex_unlock(&th->interrupt_lock); GVL_UNLOCK_END(); }