nobu / ruby-lang.org wrote:
> Since r63758, `rb_waitpid()` hangs up frequently (not always) on macOS (darwin17).
> Seems `SIGCHLD` is not delivered.

Does moving timer-thread into polling mode when there are
waitpid threads help?

```
diff --git a/signal.c b/signal.c
index 238679e1bd..ffdf645e9e 100644
--- a/signal.c
+++ b/signal.c
@@ -1066,7 +1066,7 @@ void ruby_waitpid_all(rb_vm_t *); /* process.c */
 void
 ruby_sigchld_handler(rb_vm_t *vm)
 {
-    if (sigchld_hit) {
+    if (sigchld_hit || SIGCHLD_LOSSY) {
         sigchld_hit = 0;
         ruby_waitpid_all(vm);
     }
diff --git a/thread_pthread.c b/thread_pthread.c
index 6ac7728ad9..004c9ecfe0 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1375,6 +1375,13 @@ timer_thread_sleep(rb_global_vm_lock_t* gvl)
 
     need_polling = !ubf_threads_empty();
 
+    if (SIGCHLD_LOSSY) {
+        rb_vm_t *vm = container_of(gvl, rb_vm_t, gvl);
+        if (!list_empty(&vm->waiting_pids) || !list_empty(&vm->waiting_grps)) {
+            need_polling = 1;
+        }
+    }
+
     if (gvl->waiting > 0 || need_polling) {
 	/* polling (TIME_QUANTUM_USEC usec) */
 	result = poll(pollfds, 1, TIME_QUANTUM_USEC/1000);
diff --git a/vm_core.h b/vm_core.h
index bdbe87287b..6ea3293d70 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -100,6 +100,12 @@
 #  define RUBY_SIGCHLD    (0)
 #endif
 
+#if defined(__APPLE__)
+#  define SIGCHLD_LOSSY (1)
+#else
+#  define SIGCHLD_LOSSY (0)
+#endif
+
 #ifdef HAVE_STDARG_PROTOTYPES
 #include <stdarg.h>
 #define va_init_list(a,b) va_start((a),(b))

```

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>