From 6f5aaff73b2b4e17666308dde93e1ac4edb3927d Mon Sep 17 00:00:00 2001 From: mame Date: Thu, 12 Jun 2008 13:01:38 +0000 Subject: * thread.c, vm_core.h, vm.c, thread_pthread.c, thread_win32.c: add deadlock detection. [ruby-dev:35044] * bootstraptest/test_thread.rb: add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index cece65c692..54b7677146 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -402,7 +402,7 @@ ubf_select(void *ptr) #endif static void -native_sleep(rb_thread_t *th, struct timeval *tv) +native_sleep(rb_thread_t *th, struct timeval *tv, int deadlockable) { int prev_status = th->status; struct timespec ts; @@ -418,7 +418,14 @@ native_sleep(rb_thread_t *th, struct timeval *tv) } } - th->status = THREAD_STOPPED; + if (!tv && deadlockable) { + th->status = THREAD_STOPPED_FOREVER; + th->vm->sleeper++; + rb_check_deadlock(th->vm); + } + else { + th->status = THREAD_STOPPED; + } thread_debug("native_sleep %ld\n", tv ? tv->tv_sec : -1); GVL_UNLOCK_BEGIN(); @@ -455,9 +462,10 @@ native_sleep(rb_thread_t *th, struct timeval *tv) th->unblock.arg = 0; pthread_mutex_unlock(&th->interrupt_lock); - th->status = prev_status; } GVL_UNLOCK_END(); + th->status = prev_status; + if (!tv && deadlockable) th->vm->sleeper--; RUBY_VM_CHECK_INTS(); thread_debug("native_sleep done\n"); -- cgit v1.2.3