[前][次][番号順一覧][スレッド一覧]

ruby-changes:13201

From: nobu <ko1@a...>
Date: Wed, 16 Sep 2009 16:51:21 +0900 (JST)
Subject: [ruby-changes:13201] Ruby:r24958 (ruby_1_8): * eval.c (rb_thread_start_timer): start to catch SIGVTALRM together

nobu	2009-09-16 16:51:07 +0900 (Wed, 16 Sep 2009)

  New Revision: 24958

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24958

  Log:
    * eval.c (rb_thread_start_timer): start to catch SIGVTALRM together
      with timer thread.   [ruby-core:25606]
    
    * eval.c (rb_thread_atfork): stop timer thread.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/eval.c
    branches/ruby_1_8/test/ruby/test_signal.rb

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 24957)
+++ ruby_1_8/ChangeLog	(revision 24958)
@@ -1,3 +1,10 @@
+Wed Sep 16 16:51:05 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (rb_thread_start_timer): start to catch SIGVTALRM together
+	  with timer thread.   [ruby-core:25606]
+
+	* eval.c (rb_thread_atfork): stop timer thread.
+
 Wed Sep 16 15:00:21 2009  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/matrix.rb (Scalar#/): fix bug whereby (any numeric)/(any
Index: ruby_1_8/test/ruby/test_signal.rb
===================================================================
--- ruby_1_8/test/ruby/test_signal.rb	(revision 24957)
+++ ruby_1_8/test/ruby/test_signal.rb	(revision 24958)
@@ -65,4 +65,11 @@
       w0.close
     end
   end
+
+  def test_child_vtalrm
+    return unless have_fork?	# snip this test
+    pid = fork {100_000.times{ 1+1 }}
+    pid, status = Process.wait2(pid)
+    assert_equal(false, status.signaled?, '[ruby-core:25606]')
+  end
 end
Index: ruby_1_8/eval.c
===================================================================
--- ruby_1_8/eval.c	(revision 24957)
+++ ruby_1_8/eval.c	(revision 24958)
@@ -12415,6 +12415,12 @@
 
 static int thread_init;
 
+#if defined(POSIX_SIGNAL)
+#define CATCH_VTALRM() posix_signal(SIGVTALRM, catch_timer)
+#else
+#define CATCH_VTALRM() signal(SIGVTALRM, catch_timer)
+#endif
+
 #if defined(_THREAD_SAFE)
 static void
 catch_timer(sig)
@@ -12498,6 +12504,8 @@
     static pthread_cond_t start = PTHREAD_COND_INITIALIZER;
 
     if (thread_init) return;
+    if (rb_thread_alone()) return;
+    CATCH_VTALRM();
     args[0] = &time_thread;
     args[1] = &start;
     safe_mutex_lock(&time_thread.lock);
@@ -12539,6 +12547,8 @@
     struct itimerval tval;
 
     if (thread_init) return;
+    if (rb_thread_alone()) return;
+    CATCH_VTALRM();
     tval.it_interval.tv_sec = 0;
     tval.it_interval.tv_usec = 10000;
     tval.it_value = tval.it_interval;
@@ -12618,17 +12628,11 @@
 		 "can't start a new thread (frozen ThreadGroup)");
     }
 
+#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
     if (!thread_init) {
-#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
-#if defined(POSIX_SIGNAL)
-	posix_signal(SIGVTALRM, catch_timer);
-#else
-	signal(SIGVTALRM, catch_timer);
-#endif
-
 	rb_thread_start_timer();
+    }
 #endif
-    }
 
     if (THREAD_SAVE_CONTEXT(curr_thread)) {
 	return thread;
@@ -13439,6 +13443,9 @@
     main_thread = curr_thread;
     curr_thread->next = curr_thread;
     curr_thread->prev = curr_thread;
+#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
+    rb_thread_stop_timer();
+#endif
 }
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]