* thread.c (rb_threadptr_check_signal): only wake up main thread.

* thread.c (rb_threadptr_execute_interrupts_common): check signal
  deliverly if it is main thread.
  fixes [ruby-dev:44005] [Ruby 1.9 - Bug #4950]
* bootstraptest/test_fork.rb: add a test for above.
* signal.c (rb_get_next_signal): skip if signal_buff is empty.
  (check signal_buff.size first)
* vm_core.h: remove unused variable rb_thread_t::exec_signal.
* thread.c (rb_thread_check_trap_pending): check
  rb_signal_buff_size() because rb_thread_t::exec_signal
  is no longer available.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2011-06-30 22:29:34 +00:00
parent 198c2570e7
commit fa4514e4fe
5 changed files with 58 additions and 22 deletions

View File

@ -1,3 +1,22 @@
Fri Jul 1 06:41:36 2011 Koichi Sasada <ko1@atdot.net>
* thread.c (rb_threadptr_check_signal): only wake up main thread.
* thread.c (rb_threadptr_execute_interrupts_common): check signal
deliverly if it is main thread.
fixes [ruby-dev:44005] [Ruby 1.9 - Bug #4950]
* bootstraptest/test_fork.rb: add a test for above.
* signal.c (rb_get_next_signal): skip if signal_buff is empty.
(check signal_buff.size first)
* vm_core.h: remove unused variable rb_thread_t::exec_signal.
* thread.c (rb_thread_check_trap_pending): check
rb_signal_buff_size() because rb_thread_t::exec_signal
is no longer available.
Fri Jul 1 03:28:25 2011 Yukihiro Matsumoto <matz@ruby-lang.org> Fri Jul 1 03:28:25 2011 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (Init_class_hierarchy): should name BasicObject * class.c (Init_class_hierarchy): should name BasicObject

View File

@ -47,3 +47,23 @@ assert_equal 'ok', %q{
:ok :ok
end end
}, '[ruby-core:28924]' }, '[ruby-core:28924]'
assert_equal '[1, 2]', %q{
a = []
trap(:INT) { a.push(1) }
trap(:TERM) { a.push(2) }
pid = $$
begin
fork do
sleep 0.5
Process.kill(:INT, pid)
Process.kill(:TERM, pid)
end
sleep 1
a.sort
rescue NotImplementedError
[1, 2]
end
}, '[ruby-dev:44005] [Ruby 1.9 - Bug #4950]'

View File

@ -554,16 +554,18 @@ rb_get_next_signal(void)
{ {
int i, sig = 0; int i, sig = 0;
for (i=1; i<RUBY_NSIG; i++) { if (signal_buff.size != 0) {
if (signal_buff.cnt[i] > 0) { for (i=1; i<RUBY_NSIG; i++) {
rb_disable_interrupt(); if (signal_buff.cnt[i] > 0) {
{ rb_disable_interrupt();
ATOMIC_DEC(signal_buff.cnt[i]); {
ATOMIC_DEC(signal_buff.size); ATOMIC_DEC(signal_buff.cnt[i]);
ATOMIC_DEC(signal_buff.size);
}
rb_enable_interrupt();
sig = i;
break;
} }
rb_enable_interrupt();
sig = i;
break;
} }
} }
return sig; return sig;

View File

@ -981,7 +981,7 @@ rb_thread_check_ints(void)
int int
rb_thread_check_trap_pending(void) rb_thread_check_trap_pending(void)
{ {
return GET_THREAD()->exec_signal != 0; return rb_signal_buff_size() != 0;
} }
/* This function can be called in blocking region. */ /* This function can be called in blocking region. */
@ -1269,14 +1269,15 @@ rb_threadptr_execute_interrupts_common(rb_thread_t *th)
enum rb_thread_status status = th->status; enum rb_thread_status status = th->status;
int timer_interrupt = interrupt & 0x01; int timer_interrupt = interrupt & 0x01;
int finalizer_interrupt = interrupt & 0x04; int finalizer_interrupt = interrupt & 0x04;
int sig;
th->status = THREAD_RUNNABLE; th->status = THREAD_RUNNABLE;
/* signal handling */ /* signal handling */
if (th->exec_signal) { if (th == th->vm->main_thread) {
int sig = th->exec_signal; while ((sig = rb_get_next_signal()) != 0) {
th->exec_signal = 0; rb_signal_exec(th, sig);
rb_signal_exec(th, sig); }
} }
/* exception from another thread */ /* exception from another thread */
@ -2934,14 +2935,9 @@ rb_gc_save_machine_context(rb_thread_t *th)
void void
rb_threadptr_check_signal(rb_thread_t *mth) rb_threadptr_check_signal(rb_thread_t *mth)
{ {
int sig;
/* mth must be main_thread */ /* mth must be main_thread */
if (rb_signal_buff_size() > 0) {
if (!mth->exec_signal && (sig = rb_get_next_signal()) > 0) { /* wakeup main thread */
thread_debug("main_thread: %s, sig: %d\n",
thread_status_name(mth->status), sig);
mth->exec_signal = sig;
rb_threadptr_interrupt(mth); rb_threadptr_interrupt(mth);
} }
} }

View File

@ -428,7 +428,6 @@ typedef struct rb_thread_struct {
VALUE errinfo; VALUE errinfo;
VALUE thrown_errinfo; VALUE thrown_errinfo;
int exec_signal;
rb_atomic_t interrupt_flag; rb_atomic_t interrupt_flag;
rb_thread_lock_t interrupt_lock; rb_thread_lock_t interrupt_lock;