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

ruby-changes:32947

From: usa <ko1@a...>
Date: Mon, 17 Feb 2014 18:09:37 +0900 (JST)
Subject: [ruby-changes:32947] usa:r45026 (ruby_1_9_3): merge revision(s) 43148, 43149, 43152: [Backport #8433]

usa	2014-02-17 18:09:32 +0900 (Mon, 17 Feb 2014)

  New Revision: 45026

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

  Log:
    merge revision(s) 43148,43149,43152: [Backport #8433]
    
    * thread.c (terminate_atfork_i): fix locking mutexes not unlocked in
      forks when not tracked in thread.  [ruby-core:55102] [Bug #8433]

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/test/ruby/test_thread.rb
    branches/ruby_1_9_3/thread.c
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 45025)
+++ ruby_1_9_3/ChangeLog	(revision 45026)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Mon Feb 17 18:04:40 2014  Aaron Pfeifer  <aaron.pfeifer@g...>
+
+	* thread.c (terminate_atfork_i): fix locking mutexes not unlocked in
+	  forks when not tracked in thread.  [ruby-core:55102] [Bug #8433]
+
 Fri Feb 14 21:01:12 2014  NAKAMURA Usaku  <usa@r...>
 
 	* ext/socket: revert r44943 because it causes errors on some linux
Index: ruby_1_9_3/thread.c
===================================================================
--- ruby_1_9_3/thread.c	(revision 45025)
+++ ruby_1_9_3/thread.c	(revision 45026)
@@ -345,6 +345,8 @@ typedef struct rb_mutex_struct https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L345
 } rb_mutex_t;
 
 static void rb_mutex_abandon_all(rb_mutex_t *mutexes);
+static void rb_mutex_abandon_keeping_mutexes(rb_thread_t *th);
+static void rb_mutex_abandon_locking_mutex(rb_thread_t *th);
 static const char* rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t volatile *th);
 
 void
@@ -3109,10 +3111,8 @@ terminate_atfork_i(st_data_t key, st_dat https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L3111
     GetThreadPtr(thval, th);
 
     if (th != (rb_thread_t *)current_th) {
-	if (th->keeping_mutexes) {
-	    rb_mutex_abandon_all(th->keeping_mutexes);
-	}
-	th->keeping_mutexes = NULL;
+	rb_mutex_abandon_keeping_mutexes(th);
+	rb_mutex_abandon_locking_mutex(th);
 	thread_cleanup_func(th, TRUE);
     }
     return ST_CONTINUE;
@@ -3370,8 +3370,6 @@ thgroup_add(VALUE group, VALUE thread) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L3370
 #define GetMutexPtr(obj, tobj) \
     TypedData_Get_Struct((obj), rb_mutex_t, &mutex_data_type, (tobj))
 
-static const char *rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t volatile *th);
-
 #define mutex_mark NULL
 
 static void
@@ -3688,6 +3686,28 @@ rb_mutex_unlock(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/thread.c#L3686
 }
 
 static void
+rb_mutex_abandon_keeping_mutexes(rb_thread_t *th)
+{
+    if (th->keeping_mutexes) {
+	rb_mutex_abandon_all(th->keeping_mutexes);
+    }
+    th->keeping_mutexes = NULL;
+}
+
+static void
+rb_mutex_abandon_locking_mutex(rb_thread_t *th)
+{
+    rb_mutex_t *mutex;
+
+    if (!th->locking_mutex) return;
+
+    GetMutexPtr(th->locking_mutex, mutex);
+    if (mutex->th == th)
+	rb_mutex_abandon_all(mutex);
+    th->locking_mutex = Qfalse;
+}
+
+static void
 rb_mutex_abandon_all(rb_mutex_t *mutexes)
 {
     rb_mutex_t *mutex;
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 45025)
+++ ruby_1_9_3/version.h	(revision 45026)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 534
+#define RUBY_PATCHLEVEL 535
 
-#define RUBY_RELEASE_DATE "2014-02-14"
+#define RUBY_RELEASE_DATE "2014-02-17"
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 14
+#define RUBY_RELEASE_DAY 17
 
 #include "ruby/version.h"
 
Index: ruby_1_9_3/test/ruby/test_thread.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_thread.rb	(revision 45025)
+++ ruby_1_9_3/test/ruby/test_thread.rb	(revision 45026)
@@ -710,4 +710,31 @@ class TestThreadGroup < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_thread.rb#L710
     end
     assert_in_delta(t1 - t0, 1, 1)
   end
+
+  def test_blocking_mutex_unlocked_on_fork
+    bug8433 = '[ruby-core:55102] [Bug #8433]'
+
+    mutex = Mutex.new
+    flag = false
+    mutex.lock
+
+    th = Thread.new do
+      mutex.synchronize do
+        flag = true
+        sleep
+      end
+    end
+
+    Thread.pass until th.stop?
+    mutex.unlock
+
+    pid = Process.fork do
+      exit(mutex.locked?)
+    end
+
+    th.kill
+
+    pid, status = Process.waitpid2(pid)
+    assert_equal(false, status.success?, bug8433)
+  end if Process.respond_to?(:fork)
 end

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r43148-43149,43152


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

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