[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ruby1.9.1 hangs again



Would you have time to turn that into a (tested ;) ) patch?

I tried the attached one, but it does not compile/link:

  linking ruby1.9.1
  main.o: In function `main':
  .../ruby1.9.1-1.9.3~preview1+svn33077/main.c:36:
  undefined reference to `timer_thread_child_at_fork'collect2: ld returned 1 exit status
  make[3]: *** [ruby1.9.1] Error 1

The problematic part is where to put
"pthread_atfork(NULL, NULL, timer_thread_child_at_fork)"

Do you have some idea ?

Petr
--- ruby1.9.1-1.9.3~preview1+svn33077.orig/thread_pthread.c
+++ ruby1.9.1-1.9.3~preview1+svn33077/thread_pthread.c
@@ -1045,6 +1045,33 @@ static pthread_t timer_thread_id;
 static int timer_thread_pipe[2] = {-1, -1};
 static int timer_thread_pipe_owner_process;
 
+#if 0
+static inline int 
+timer_thread_running() {
+   return timer_thread_pipe_owner_process == getpid() ? 1 : 0;
+}
+   
+static inline void timer_thread_set() {
+    timer_thread_pipe_owner_process = getpid();
+}
+      
+void timer_thread_child_at_fork() {
+}
+#else
+static inline int 
+timer_thread_running() {
+   return timer_thread_pipe_owner_process;
+}
+   
+static inline void timer_thread_set() {
+    timer_thread_pipe_owner_process = 1;
+}
+      
+void timer_thread_child_at_fork() {
+    timer_thread_pipe_owner_process = 0;
+}
+#endif
+
 #define TT_DEBUG 0
 
 #define WRITE_CONST(fd, str) (void)(write((fd),(str),sizeof(str)-1)<0)
@@ -1056,7 +1083,7 @@ rb_thread_wakeup_timer_thread(void)
     ssize_t result;
 
     /* already opened */
-    if (timer_thread_pipe_owner_process == getpid()) {
+    if (timer_thread_running()) {
 	const char *buff = "!";
       retry:
 	if ((result = write(timer_thread_pipe[1], buff, 1)) <= 0) {
@@ -1199,7 +1226,7 @@ rb_thread_create_timer_thread(void)
 #endif
 
 	/* communication pipe with timer thread and signal handler */
-	if (timer_thread_pipe_owner_process != getpid()) {
+	if (!timer_thread_running()) {
 	    if (timer_thread_pipe[0] != -1) {
 		/* close pipe of parent process */
 		close_communication_pipe();
@@ -1229,7 +1256,7 @@ rb_thread_create_timer_thread(void)
 #endif /* defined(HAVE_FCNTL) && defined(F_GETFL) && defined(F_SETFL) */
 
 	    /* validate pipe on this process */
-	    timer_thread_pipe_owner_process = getpid();
+	    timer_thread_set();
 	}
 
 	/* create timer thread */
--- ruby1.9.1-1.9.3~preview1+svn33077.orig/main.c
+++ ruby1.9.1-1.9.3~preview1+svn33077/main.c
@@ -21,6 +21,8 @@
 
 RUBY_GLOBAL_SETUP
 
+extern void timer_thread_child_at_fork();
+
 int
 main(int argc, char **argv)
 {
@@ -31,6 +33,8 @@ main(int argc, char **argv)
     setlocale(LC_CTYPE, "");
 #endif
 
+    pthread_atfork(NULL, NULL, timer_thread_child_at_fork);
+    
     ruby_sysinit(&argc, &argv);
     {
 	RUBY_INIT_STACK;

Reply to: