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

ruby-changes:46265

From: nobu <ko1@a...>
Date: Sun, 16 Apr 2017 23:27:28 +0900 (JST)
Subject: [ruby-changes:46265] nobu:r58370 (trunk): thread_win32.c: no GVL for interrupt_event

nobu	2017-04-16 23:27:21 +0900 (Sun, 16 Apr 2017)

  New Revision: 58370

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58370

  Log:
    thread_win32.c: no GVL for interrupt_event
    
    * thread_win32.c (w32_wait_events): do not acquire GVL, to fix
      deadlock at read/close race condition.  instead, just ignore
      interrupt_event if it is closed.

  Modified files:
    trunk/thread_win32.c
Index: thread_win32.c
===================================================================
--- thread_win32.c	(revision 58369)
+++ thread_win32.c	(revision 58370)
@@ -158,22 +158,6 @@ Init_native_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L158
 		 th->native_thread_data.interrupt_event);
 }
 
-static void
-w32_set_event(HANDLE handle)
-{
-    if (SetEvent(handle) == 0) {
-	w32_error("w32_set_event");
-    }
-}
-
-static void
-w32_reset_event(HANDLE handle)
-{
-    if (ResetEvent(handle) == 0) {
-	w32_error("w32_reset_event");
-    }
-}
-
 static int
 w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
 {
@@ -184,20 +168,16 @@ w32_wait_events(HANDLE *events, int coun https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L168
     thread_debug("  w32_wait_events events:%p, count:%d, timeout:%ld, th:%p\n",
 		 events, count, timeout, th);
     if (th && (intr = th->native_thread_data.interrupt_event)) {
-	gvl_acquire(th->vm, th);
-	if (intr == th->native_thread_data.interrupt_event) {
-	    w32_reset_event(intr);
-	    if (RUBY_VM_INTERRUPTED(th)) {
-		w32_set_event(intr);
-	    }
-
+	if (ResetEvent(intr) && (!RUBY_VM_INTERRUPTED(th) || SetEvent(intr))) {
 	    targets = ALLOCA_N(HANDLE, count + 1);
 	    memcpy(targets, events, sizeof(HANDLE) * count);
 
 	    targets[count++] = intr;
 	    thread_debug("  * handle: %p (count: %d, intr)\n", intr, count);
 	}
-	gvl_release(th->vm);
+	else if (intr == th->native_thread_data.interrupt_event) {
+	    w32_error("w32_wait_events");
+	}
     }
 
     thread_debug("  WaitForMultipleObjects start (count: %d)\n", count);
@@ -682,7 +662,9 @@ ubf_handle(void *ptr) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L662
     rb_thread_t *th = (rb_thread_t *)ptr;
     thread_debug("ubf_handle: %p\n", th);
 
-    w32_set_event(th->native_thread_data.interrupt_event);
+    if (!SetEvent(th->native_thread_data.interrupt_event)) {
+	w32_error("ubf_handle");
+    }
 }
 
 static struct {

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

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