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

ruby-changes:45522

From: ko1 <ko1@a...>
Date: Fri, 10 Feb 2017 17:15:45 +0900 (JST)
Subject: [ruby-changes:45522] ko1:r57595 (trunk): check thread deadness correctly.

ko1	2017-02-10 17:15:39 +0900 (Fri, 10 Feb 2017)

  New Revision: 57595

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57595

  Log:
    check thread deadness correctly.

  Modified files:
    trunk/test/ruby/test_thread.rb
    trunk/thread.c
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 57594)
+++ test/ruby/test_thread.rb	(revision 57595)
@@ -1160,4 +1160,14 @@ q.pop https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L1160
     c = Class.new(Thread) {def initialize() self.name = "foo"; super; end}
     assert_equal("foo", c.new {Thread.current.name}.value, bug12290)
   end
+
+  def test_thread_interrupt_for_killed_thread
+    assert_normal_exit(<<-_end, '[Bug #8996]', timeout: 5, timeout_error: nil)
+      trap(:TERM){exit}
+      while true
+        t = Thread.new{sleep 0}
+        t.raise Interrupt
+      end
+    _end
+  end
 end
Index: thread.c
===================================================================
--- thread.c	(revision 57594)
+++ thread.c	(revision 57595)
@@ -2107,6 +2107,13 @@ rb_threadptr_raise(rb_thread_t *th, int https://github.com/ruby/ruby/blob/trunk/thread.c#L2107
     else {
 	exc = rb_make_exception(argc, argv);
     }
+
+    /* making an exception object can switch thread,
+       so we need to check thread deadness again */
+    if (rb_threadptr_dead(th)) {
+	return Qnil;
+    }
+
     rb_threadptr_setup_exception(GET_THREAD(), exc, Qundef);
     rb_threadptr_pending_interrupt_enque(th, exc);
     rb_threadptr_interrupt(th);

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

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