summaryrefslogtreecommitdiff
path: root/thread_sync.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-16 19:59:21 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-16 19:59:21 +0000
commit2cf3bd5bb2a7c4724e528577d37a883fe80a1122 (patch)
treea079c81d0fb825573535071946231ab613b3f923 /thread_sync.c
parent4bf11e21f958380dd2cf0f48a1fec2d992a85146 (diff)
thread_sync.c (rb_mutex_lock): acquire lock before being killed
We (the thread acquiring the mutex) need to acquire the mutex before being killed to work with ConditionVariable#wait. Thus we reinstate the acquire-immediately-after-sleeping logic from pre-r63711 while still retaining the acquire-after-checking-for-interrupts logic from r63711. This regression was introduced in commit 501069b8a4013f2e3fdde35c50e9527ef0061963 (r63711) ("thread_sync.c (rb_mutex_lock): fix deadlock") for [Bug #14841] [ruby-core:88503] [Bug #14999] [Bug #14841] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_sync.c')
-rw-r--r--thread_sync.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/thread_sync.c b/thread_sync.c
index 279c644093..5e511af0db 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -272,17 +272,23 @@ rb_mutex_lock(VALUE self)
list_add_tail(&mutex->waitq, &w.node);
native_sleep(th, timeout); /* release GVL */
list_del(&w.node);
+
+ if (!mutex->th) {
+ mutex->th = th;
+ }
+
if (patrol_thread == th)
patrol_thread = NULL;
th->locking_mutex = Qfalse;
- if (timeout && !RUBY_VM_INTERRUPTED(th->ec)) {
+ if (mutex->th && timeout && !RUBY_VM_INTERRUPTED(th->ec)) {
rb_check_deadlock(th->vm);
}
if (th->status == THREAD_STOPPED_FOREVER) {
th->status = prev_status;
}
th->vm->sleeper--;
+ if (mutex->th == th) mutex_locked(th, self);
RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */
if (!mutex->th) {