diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-16 07:51:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-16 07:51:07 +0000 |
commit | ce897307b0837ec5c1fc75fdc8ccf1f168741dbe (patch) | |
tree | 24108b89ccce9e2fc664c6f9325bd4c3a6cbcd7c | |
parent | 7239e8e06e69972aed1d7991f684a214c2bb896d (diff) |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@24958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | eval.c | 23 | ||||
-rw-r--r-- | test/ruby/test_signal.rb | 7 |
3 files changed, 29 insertions, 8 deletions
@@ -1,3 +1,10 @@ +Wed Sep 16 16:51:05 2009 Nobuyoshi Nakada <[email protected]> + + * 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 <[email protected]> * lib/matrix.rb (Scalar#/): fix bug whereby (any numeric)/(any @@ -12415,6 +12415,12 @@ rb_thread_alloc(klass) 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 @@ rb_thread_start_timer() 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 @@ rb_thread_start_timer() 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 @@ rb_thread_start_0(fn, arg, th) "can't start a new thread (frozen ThreadGroup)"); } - 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 - + if (!thread_init) { rb_thread_start_timer(); -#endif } +#endif if (THREAD_SAVE_CONTEXT(curr_thread)) { return thread; @@ -13439,6 +13443,9 @@ rb_thread_atfork() 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 } diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb index 43e16b8c79..84db7fa1f3 100644 --- a/test/ruby/test_signal.rb +++ b/test/ruby/test_signal.rb @@ -65,4 +65,11 @@ class TestSignal < Test::Unit::TestCase 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 |