mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
2e248ad5aa
commit
82e6d95edc
3 changed files with 27 additions and 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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue