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

ruby-changes:54217

From: normal <ko1@a...>
Date: Tue, 18 Dec 2018 18:21:10 +0900 (JST)
Subject: [ruby-changes:54217] normal:r66438 (trunk): thread_sync.c (mutex_ptr): only reinitalize waitqueue at fork

normal	2018-12-18 18:21:05 +0900 (Tue, 18 Dec 2018)

  New Revision: 66438

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

  Log:
    thread_sync.c (mutex_ptr): only reinitalize waitqueue at fork
    
    Mutexes need to remain locked after forking.
    
    This fixes "[BUG] invalid keeping_mutexes: Attempt to unlock a
    mutex which is locked by another thread" and should
    fix test_fork_while_parent_locked failures in CI
    
    [ruby-core:90581] [Bug #15424]
    [ruby-core:90595] [Bug #15430]
    
    Fixes: r66230 ("handle mutexes held by parent threads in children")

  Modified files:
    trunk/test/ruby/test_thread.rb
    trunk/thread_sync.c
Index: thread_sync.c
===================================================================
--- thread_sync.c	(revision 66437)
+++ thread_sync.c	(revision 66438)
@@ -130,8 +130,6 @@ mutex_ptr(VALUE obj) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L130
         /* forked children can't reach into parent thread stacks */
         mutex->fork_gen = fork_gen;
         list_head_init(&mutex->waitq);
-        mutex->next_mutex = 0;
-        mutex->th = 0;
     }
 
     return mutex;
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 66437)
+++ test/ruby/test_thread.rb	(revision 66438)
@@ -1260,6 +1260,21 @@ q.pop https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L1260
     assert_equal 0, failures, '[ruby-core:90312] [Bug #15383]'
   end
 
+  def test_fork_while_mutex_locked_by_forker
+    skip 'needs fork' unless Process.respond_to?(:fork)
+    m = Mutex.new
+    m.synchronize do
+      pid = fork do
+        exit!(2) unless m.locked?
+        m.unlock rescue exit!(3)
+        m.synchronize {} rescue exit!(4)
+        exit!(0)
+      end
+      _, st = Timeout.timeout(30) { Process.waitpid2(pid) }
+      assert_predicate st, :success?, '[ruby-core:90595] [Bug #15430]'
+    end
+  end
+
   def test_subclass_no_initialize
     t = Module.new do
       break eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")

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

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