Hi,

In message "Re: --enable-pthread broken?"
    on 03/12/12, Nathaniel Talbott <nathaniel / talbott.ws> writes:

|            |                    enable-pthread                |
|            | with (unpatched) | with (patched) | without      |
|---------------------------------------------------------------
|  Main app  | segfault         | untested       | blocked      |
|---------------------------------------------------------------
|killer.rb  | segfault         | blocked        | inconclusive |
|
|I hope this helps; please let me know if there's any more information 
|you need. I'll let you know if I manage to get killer.rb to block 
|without --enable-pthread.

LinuxThread has something bad with signal handling, I guess.  This
patch may solve the blocking problem at the cost of potential
performance slow down.  Can you try (with --enable-pthread)?

							matz.

--- eval.c	13 Dec 2003 00:01:28 -0000	1.603
+++ eval.c	13 Dec 2003 02:00:21 -0000
@@ -9487,3 +9487,63 @@ rb_thread_alloc(klass)
 
-#if defined(HAVE_SETITIMER)
+static int thread_init = 0;
+
+#if defined(HAVE_LIBPTHREAD) && defined(_REENTRANT)
+# define PTHREAD_TIMER
+#endif
+
+#if defined(POSIX_SIGNAL)
+# define ruby_signal(x,y) posix_signal((x), (y))
+#else
+# define ruby_signal(x,y) signal((x), (y))
+#endif
+
+#if defined(PTHREAD_TIMER)
+static pthread_t time_thread;
+
+static void
+catch_timer(sig)
+    int sig;
+{
+#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
+    signal(sig, catch_timer);
+#endif
+    rb_thread_schedule();
+}
+
+static void*
+thread_timer(dummy)
+    void *dummy;
+{
+    struct timespec req, rem;
+
+    for (;;) {
+	if (!rb_thread_critical) {
+#if 1
+	    if (rb_trap_immediate) {
+		pthread_kill(ruby_thid, SIGVTALRM);
+	    }
+	    else {
+		rb_thread_pending = 1;
+	    }
+#else
+	    rb_thread_pending = 1;
+#endif
+	    req.tv_sec = 0;
+	    req.tv_nsec = 10000000;
+	    nanosleep(&req, &rem);
+	}
+    }
+}
+
+void
+rb_thread_start_timer()
+{
+}
+
+void
+rb_thread_stop_timer()
+{
+}
+#elif defined(HAVE_SETITIMER)
+
 static void
@@ -9502,8 +9562,2 @@ catch_timer(sig)
 }
-#else
-int rb_thread_tick = THREAD_TICK;
-#endif
-
-#if defined(HAVE_SETITIMER)
-static int thread_init = 0;
 
@@ -9532,2 +9586,4 @@ rb_thread_stop_timer()
 }
+#else
+int rb_thread_tick = THREAD_TICK;
 #endif
@@ -9551,14 +9607,14 @@ rb_thread_start_0(fn, arg, th)
 
-#if defined(HAVE_SETITIMER)
     if (!thread_init) {
-#ifdef POSIX_SIGNAL
-	posix_signal(SIGVTALRM, catch_timer);
-#else
-	signal(SIGVTALRM, catch_timer);
-#endif
-
 	thread_init = 1;
+#if defined(HAVE_SETITIMER) || defined(PTHREAD_TIMER)
+	ruby_signal(SIGVTALRM, catch_timer);
+
+#ifdef PTHREAD_TIMER
+	pthread_create(&time_thread, 0, thread_timer, 0);
+#else
 	rb_thread_start_timer();
-    }
 #endif
+#endif
+    }