diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-14 16:31:23 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-14 16:31:23 +0000 |
commit | 82e6d95edc047cf39ac3e3c5f388c5624a35d77a (patch) | |
tree | e4b81dca1ef7ff2a09d0ec4c6ebf2bb3a265f80d | |
parent | 2e248ad5aa32cabb657fe214927b848d183f6d84 (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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | thread_pthread.c | 23 | ||||
-rw-r--r-- | thread_pthread.h | 4 |
3 files changed, 27 insertions, 7 deletions
@@ -1,3 +1,10 @@ +Wed Jun 15 01:27:53 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com> + + * 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. + Tue Jun 14 23:16:22 2011 Tanaka Akira <akr@fsij.org> * bootstraptest/runner.rb (show_progress): refine verbose mode. 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; diff --git a/thread_pthread.h b/thread_pthread.h index 781712c3f6..3167efc050 100644 --- a/thread_pthread.h +++ b/thread_pthread.h @@ -45,7 +45,9 @@ typedef struct rb_global_vm_lock_struct { /* yield */ rb_thread_cond_t switch_cond; - unsigned long need_yield; + rb_thread_cond_t switch_wait_cond; + int need_yield; + int wait_yield; } rb_global_vm_lock_t; #endif /* RUBY_THREAD_PTHREAD_H */ |