[前][次][番号順一覧][スレッド一覧]

ruby-changes:19975

From: kosaki <ko1@a...>
Date: Sun, 12 Jun 2011 15:58:26 +0900 (JST)
Subject: [ruby-changes:19975] kosaki:r32022 (trunk): * thread.c: remove th->transition_for_lock. It's thread unsafe.

kosaki	2011-06-12 15:58:15 +0900 (Sun, 12 Jun 2011)

  New Revision: 32022

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32022

  Log:
    * thread.c: remove th->transition_for_lock. It's thread unsafe.
      [Bug #4723][ruby-dev:43563]

  Modified files:
    trunk/ChangeLog
    trunk/thread.c
    trunk/vm_core.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32021)
+++ ChangeLog	(revision 32022)
@@ -1,3 +1,8 @@
+Sun Jun 12 15:56:08 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* thread.c: remove th->transition_for_lock. It's thread unsafe.
+	  [Bug #4723][ruby-dev:43563]
+
 Sun Jun 12 15:47:35 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* thread.c: introduce spurious wakeup safe deadlock check.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 32021)
+++ vm_core.h	(revision 32022)
@@ -436,7 +436,6 @@
     struct rb_unblock_callback unblock;
     VALUE locking_mutex;
     struct rb_mutex_struct *keeping_mutexes;
-    volatile int transition_for_lock;
 
     struct rb_vm_tag *tag;
     struct rb_vm_protect_tag *protect_tag;
Index: thread.c
===================================================================
--- thread.c	(revision 32021)
+++ thread.c	(revision 32022)
@@ -3459,9 +3459,6 @@
     int interrupted = 0;
     int err = 0;
 
-    native_mutex_lock(&mutex->lock);
-    th->transition_for_lock = 0;
-
     mutex->cond_waiting++;
     for (;;) {
 	if (!mutex->th) {
@@ -3493,9 +3490,6 @@
     }
     mutex->cond_waiting--;
 
-    th->transition_for_lock = 1;
-    native_mutex_unlock(&mutex->lock);
-
     return interrupted;
 }
 
@@ -3537,23 +3531,23 @@
 
 	    set_unblock_function(th, lock_interrupt, mutex, &oldubf);
 	    th->status = THREAD_STOPPED_FOREVER;
-	    th->vm->sleeper++;
 	    th->locking_mutex = self;
 
+	    native_mutex_lock(&mutex->lock);
+	    th->vm->sleeper++;
 	    /*
-	     * Carefully! while some contended threads are in lock_fun(),
+	     * Carefully! while some contended threads are in lock_func(),
 	     * vm->sleepr is unstable value. we have to avoid both deadlock
 	     * and busy loop.
 	     */
 	    if (vm_living_thread_num(th->vm) == th->vm->sleeper) {
 		timeout_ms = 100;
 	    }
+	    GVL_UNLOCK_BEGIN();
+	    interrupted = lock_func(th, mutex, timeout_ms);
+	    native_mutex_unlock(&mutex->lock);
+	    GVL_UNLOCK_END();
 
-	    th->transition_for_lock = 1;
-	    BLOCKING_REGION_CORE({
-		interrupted = lock_func(th, mutex, timeout_ms);
-	    });
-	    th->transition_for_lock = 0;
 	    reset_unblock_function(th, &oldubf);
 
 	    th->locking_mutex = Qfalse;
@@ -4728,7 +4722,7 @@
     rb_thread_t *th;
     GetThreadPtr(thval, th);
 
-    if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th) || th->transition_for_lock) {
+    if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th)) {
 	*found = 1;
     }
     else if (th->locking_mutex) {
@@ -4753,7 +4747,7 @@
     rb_thread_t *th;
     GetThreadPtr(thval, th);
 
-    printf("th:%p %d %d %d", th, th->status, th->interrupt_flag, th->transition_for_lock);
+    printf("th:%p %d %d", th, th->status, th->interrupt_flag);
     if (th->locking_mutex) {
 	mutex_t *mutex;
 	GetMutexPtr(th->locking_mutex, mutex);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]