aboutsummaryrefslogtreecommitdiffstats
path: root/test/thread/test_cv.rb
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-27 09:28:37 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-27 09:28:37 +0000
commita2d63ea2fb84c962abddae877e9493fc57cfce1a (patch)
tree4503e0aa911338f50abdcc580a169d56f9f14a9a /test/thread/test_cv.rb
parent98e9444b5f33873fa3e8e8cdd4143771b1bc477e (diff)
downloadruby-a2d63ea2fb84c962abddae877e9493fc57cfce1a.tar.gz
thread_sync.c: avoid reaching across stacks of dead threads
rb_ensure is insufficient cleanup for fork and we must reinitialize all waitqueues in the child process. Unfortunately this increases the footprint of ConditionVariable, Queue and SizedQueue by 8 bytes on 32-bit (16 bytes on 64-bit). [ruby-core:86316] [Bug #14634] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/thread/test_cv.rb')
-rw-r--r--test/thread/test_cv.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb
index 70cf4483a3..a093f373b1 100644
--- a/test/thread/test_cv.rb
+++ b/test/thread/test_cv.rb
@@ -219,4 +219,23 @@ INPUT
Marshal.dump(condvar)
end
end
+
+ def test_condvar_fork
+ mutex = Mutex.new
+ condvar = ConditionVariable.new
+ thrs = (1..10).map do
+ Thread.new { mutex.synchronize { condvar.wait(mutex) } }
+ end
+ thrs.each { 3.times { Thread.pass } }
+ pid = fork do
+ mutex.synchronize { condvar.broadcast }
+ exit!(0)
+ end
+ _, s = Process.waitpid2(pid)
+ assert_predicate s, :success?, 'no segfault [ruby-core:86316] [Bug #14634]'
+ until thrs.empty?
+ mutex.synchronize { condvar.broadcast }
+ thrs.delete_if { |t| t.join(0.01) }
+ end
+ end if Process.respond_to?(:fork)
end