diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-10 04:32:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-10 04:32:22 +0000 |
commit | 9883632d6ad6dec664047df38f8098ef46963bb0 (patch) | |
tree | 09d9a80759af2081bfa13858f70583c2b6f37184 | |
parent | a46e21c86fd2be677d7565c501160f1ce638f81b (diff) | |
download | ruby-9883632d6ad6dec664047df38f8098ef46963bb0.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 21 | ||||
-rw-r--r-- | thread.c | 3 |
3 files changed, 30 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sat May 10 13:32:18 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@gmail.com> * man/ruby.1: remove deadlink. [ruby-core:62145][Bug #9773] diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 8da774e664..70f6d5d639 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -973,4 +973,25 @@ Thread.new(Thread.current) {|mth| 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 @@ -569,6 +569,9 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s 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); |