summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-19 16:28:06 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-19 16:28:06 +0000
commit0bdfc7243fe2d815aff62f4467663c52062cfbf2 (patch)
treeab12dc58ad9dd58be6f9d89a57ca04af93dc6086
parentaeecc27f842a93aedcc0177c2eae738a7c87c821 (diff)
merge revision(s) r43148,r43149,r43152: [Backport #8433]
* thread.c (terminate_atfork_i): fix locking mutexes not unlocked in forks when not tracked in thread. [ruby-core:55102] [Bug #8433] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@45049 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_thread.rb27
-rw-r--r--thread.c32
-rw-r--r--version.h2
4 files changed, 59 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index a55a44ab50..d80689003b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Feb 20 01:23:36 2014 Aaron Pfeifer <aaron.pfeifer@gmail.com>
+
+ * thread.c (terminate_atfork_i): fix locking mutexes not unlocked in
+ forks when not tracked in thread. [ruby-core:55102] [Bug #8433]
+
Tue Feb 18 23:48:03 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/ruby/envutil.rb (assert_separately): require envutil in the
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 4aed34d5ba..9ac2c30710 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -937,4 +937,31 @@ Thread.new(Thread.current) {|mth|
size_large = invoke_rec script, vm_stack_size, 1024 * 1024 * 10
assert_operator(size_default, :<=, size_large, "large size")
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
diff --git a/thread.c b/thread.c
index d859982fe5..142ed5dbf5 100644
--- a/thread.c
+++ b/thread.c
@@ -384,6 +384,8 @@ typedef struct rb_mutex_struct
} 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
@@ -3832,10 +3834,8 @@ terminate_atfork_i(st_data_t key, st_data_t val, st_data_t current_th)
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;
@@ -4099,8 +4099,6 @@ thgroup_add(VALUE group, VALUE thread)
#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
@@ -4432,6 +4430,28 @@ rb_mutex_unlock(VALUE self)
}
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;
diff --git a/version.h b/version.h
index 28996b299e..1abb56c0cf 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2014-02-20"
-#define RUBY_PATCHLEVEL 437
+#define RUBY_PATCHLEVEL 438
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 2