diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-09 06:27:02 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-09 06:27:02 +0000 |
commit | 10c14095de5dd4114d8cf536c5bd4cea63370a97 (patch) | |
tree | 3fa94d36c179ebc2ff871050f1948db2a65ae2bc /thread.c | |
parent | 5fbfc21b67f4bd68502e186024636f5bf4350f90 (diff) | |
download | ruby-10c14095de5dd4114d8cf536c5bd4cea63370a97.tar.gz |
* thread.c (rb_mutex_lock): stop multiple threads use
pthread_cond_timedwait() concurrently. [Bug #6278] [ruby-core:44275]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -3911,6 +3911,13 @@ lock_interrupt(void *ptr) } /* + * At maximum, only one thread can use cond_timedwait and watch deadlock + * periodically. Multiple polling thread (i.e. concurrent deadlock check) + * introduces new race conditions. [Bug #6278] [ruby-core:44275] + */ +rb_thread_t *patrol_thread = NULL; + +/* * call-seq: * mutex.lock -> self * @@ -3947,14 +3954,20 @@ rb_mutex_lock(VALUE self) * vm->sleepr is unstable value. we have to avoid both deadlock * and busy loop. */ - if (vm_living_thread_num(th->vm) == th->vm->sleeper) { + if ((vm_living_thread_num(th->vm) == th->vm->sleeper) && + !patrol_thread) { timeout_ms = 100; + patrol_thread = th; } + GVL_UNLOCK_BEGIN(); interrupted = lock_func(th, mutex, timeout_ms); native_mutex_unlock(&mutex->lock); GVL_UNLOCK_END(); + if (patrol_thread == th) + patrol_thread = NULL; + reset_unblock_function(th, &oldubf); th->locking_mutex = Qfalse; @@ -4642,6 +4655,7 @@ rb_check_deadlock(rb_vm_t *vm) if (vm_living_thread_num(vm) > vm->sleeper) return; if (vm_living_thread_num(vm) < vm->sleeper) rb_bug("sleeper must not be more than vm_living_thread_num(vm)"); + if (patrol_thread && patrol_thread != GET_THREAD()) return; st_foreach(vm->living_threads, check_deadlock_i, (st_data_t)&found); |