ruby-changes:60711
From: Koichi <ko1@a...>
Date: Thu, 9 Apr 2020 12:52:12 +0900 (JST)
Subject: [ruby-changes:60711] fd0222caed (master): should check pending interrupts correctly.
https://git.ruby-lang.org/ruby.git/commit/?id=fd0222caed From fd0222caedf1be56faa004656bbf145522abbe68 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Thu, 9 Apr 2020 04:45:49 +0900 Subject: should check pending interrupts correctly. rb_uninterruptible() disables any interrupts using handle_interrupt feature (This function is used by `p`). After this function, pending interrupts should be checked correctly, however there is no chance to setup interrupt flag of working threads, it means that nobody checks pending interrupts. For example, it ignores terminate signal delivered at the end of main thread and program can't stop. This patch set interrupt flag if there are pending interrupts. diff --git a/bootstraptest/test_thread.rb b/bootstraptest/test_thread.rb index e7ddadf..38a55ff 100644 --- a/bootstraptest/test_thread.rb +++ b/bootstraptest/test_thread.rb @@ -484,3 +484,17 @@ assert_equal 'foo', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_thread.rb#L484 GC.start f.call.source } +assert_normal_exit %q{ + class C + def inspect + sleep 0.5 + 'C!!' + end + end + Thread.new{ + loop{ + p C.new + } + } + sleep 0.1 +}, timeout: 5 diff --git a/thread.c b/thread.c index e59b6db..ccfa870 100644 --- a/thread.c +++ b/thread.c @@ -5564,6 +5564,19 @@ rb_default_coverage(int n) https://github.com/ruby/ruby/blob/trunk/thread.c#L5564 return coverage; } +static VALUE +uninterruptible_exit(VALUE v) +{ + rb_thread_t *cur_th = GET_THREAD(); + rb_ary_pop(cur_th->pending_interrupt_mask_stack); + + cur_th->pending_interrupt_queue_checked = 0; + if (!rb_threadptr_pending_interrupt_empty_p(cur_th)) { + RUBY_VM_SET_INTERRUPT(cur_th->ec); + } + return Qnil; +} + VALUE rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data) { @@ -5574,5 +5587,8 @@ rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data) https://github.com/ruby/ruby/blob/trunk/thread.c#L5587 OBJ_FREEZE_RAW(interrupt_mask); rb_ary_push(cur_th->pending_interrupt_mask_stack, interrupt_mask); - return rb_ensure(b_proc, data, rb_ary_pop, cur_th->pending_interrupt_mask_stack); + VALUE ret = rb_ensure(b_proc, data, uninterruptible_exit, Qnil); + + RUBY_VM_CHECK_INTS(cur_th->ec); + return ret; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/