summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-14 16:31:23 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-14 16:31:23 +0000
commit82e6d95edc047cf39ac3e3c5f388c5624a35d77a (patch)
treee4b81dca1ef7ff2a09d0ec4c6ebf2bb3a265f80d /thread_pthread.c
parent2e248ad5aa32cabb657fe214927b848d183f6d84 (diff)
* thread_pthread.c (gvl_yield): fix live lock issue on 1-2 cpus
system. It's additional fix for r32021. * thread_pthread.c (gvl_init): add switch_wait_cond. * thread_pthread.h (typedef struct rb_global_vm_lock_struct): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 3954fc04c4..3a5c2c7e3c 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -88,25 +88,35 @@ gvl_yield(rb_vm_t *vm, rb_thread_t *th)
{
native_mutex_lock(&vm->gvl.lock);
+ __gvl_release(vm);
+
/* An another thread is processing GVL yield. */
- if (vm->gvl.need_yield) {
- native_mutex_unlock(&vm->gvl.lock);
- return;
+ if (UNLIKELY(vm->gvl.wait_yield)) {
+ while (vm->gvl.wait_yield)
+ native_cond_wait(&vm->gvl.switch_wait_cond, &vm->gvl.lock);
+ goto acquire;
}
+ vm->gvl.wait_yield = 1;
+
if (vm->gvl.waiting > 0)
vm->gvl.need_yield = 1;
- __gvl_release(vm);
if (vm->gvl.need_yield) {
/* Wait until another thread task take GVL. */
- native_cond_wait(&vm->gvl.switch_cond, &vm->gvl.lock);
- } else {
+ while (vm->gvl.need_yield) {
+ native_cond_wait(&vm->gvl.switch_cond, &vm->gvl.lock);
+ }
+ }
+ else {
native_mutex_unlock(&vm->gvl.lock);
sched_yield();
native_mutex_lock(&vm->gvl.lock);
}
+ vm->gvl.wait_yield = 0;
+ native_cond_broadcast(&vm->gvl.switch_wait_cond);
+ acquire:
__gvl_acquire(vm);
native_mutex_unlock(&vm->gvl.lock);
}
@@ -119,6 +129,7 @@ gvl_init(rb_vm_t *vm)
native_mutex_initialize(&vm->gvl.lock);
native_cond_initialize(&vm->gvl.cond, RB_CONDATTR_CLOCK_MONOTONIC);
native_cond_initialize(&vm->gvl.switch_cond, RB_CONDATTR_CLOCK_MONOTONIC);
+ native_cond_initialize(&vm->gvl.switch_wait_cond, RB_CONDATTR_CLOCK_MONOTONIC);
vm->gvl.acquired = 0;
vm->gvl.waiting = 0;
vm->gvl.need_yield = 0;