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

ruby-changes:33818

From: nobu <ko1@a...>
Date: Sat, 10 May 2014 13:32:38 +0900 (JST)
Subject: [ruby-changes:33818] nobu:r45899 (trunk): thread.c: stop if forked in a sub-thread

nobu	2014-05-10 13:32:22 +0900 (Sat, 10 May 2014)

  New Revision: 45899

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

  Log:
    thread.c: stop if forked in a sub-thread
    
    * thread.c (thread_start_func_2): stop if forked in a sub-thread,
      the thread has become the main thread.
      [ruby-core:62070] [Bug #9751]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_thread.rb
    trunk/thread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45898)
+++ ChangeLog	(revision 45899)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May 10 13:32:18 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (thread_start_func_2): stop if forked in a sub-thread,
+	  the thread has become the main thread.
+	  [ruby-core:62070] [Bug #9751]
+
 Sat May 10 09:32:19 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* man/ruby.1: remove deadlink. [ruby-core:62145][Bug #9773]
Index: thread.c
===================================================================
--- thread.c	(revision 45898)
+++ thread.c	(revision 45899)
@@ -569,6 +569,9 @@ thread_start_func_2(rb_thread_t *th, VAL https://github.com/ruby/ruby/blob/trunk/thread.c#L569
 	thread_debug("thread end: %p\n", (void *)th);
 
 	main_th = th->vm->main_thread;
+	if (main_th == th) {
+	    ruby_stop(0);
+	}
 	if (RB_TYPE_P(errinfo, T_OBJECT)) {
 	    /* treat with normal error object */
 	    rb_threadptr_raise(main_th, 1, &errinfo);
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 45898)
+++ test/ruby/test_thread.rb	(revision 45899)
@@ -973,4 +973,25 @@ Thread.new(Thread.current) {|mth| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L973
     pid, status = Process.waitpid2(pid)
     assert_equal(false, status.success?, bug8433)
   end if Process.respond_to?(:fork)
+
+  def test_fork_in_thread
+    bug9751 = '[ruby-core:62070] [Bug #9751]'
+    f = nil
+    th = Thread.start do
+      unless f = IO.popen("-")
+        STDERR.reopen(STDOUT)
+        exit
+      end
+      Process.wait2(f.pid)
+    end
+    unless th.join(3)
+      Process.kill(:QUIT, f.pid)
+      Process.kill(:KILL, f.pid) unless th.join(1)
+    end
+    _, status = th.value
+    output = f.read
+    f.close
+    assert_not_predicate(status, :signaled?, FailDesc[status, bug9751, output])
+    assert_predicate(status, :success?, bug9751)
+  end if Process.respond_to?(:fork)
 end

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

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