From ef763e7d0c1f7b1d1e3a2b6ed593fd324c3264e9 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 30 Jun 2017 10:44:46 +0000 Subject: merge revision(s) 58370,58382: [Backport #13530] 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. thread_win32.c: fix index * thread_win32.c (w32_wait_events): fix wait object index in the case of interrupt_event is not usable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ thread_win32.c | 35 +++++++++-------------------------- version.h | 2 +- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed76e7e07c..bf26c22468 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Jun 30 19:41:48 2017 Nobuyoshi Nakada + + * 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. + + * thread_win32.c (w32_wait_events): fix wait object index in the case of + interrupt_event is not usable. + Fri Jun 30 19:37:47 2017 KOSAKI Motohiro * io.c (nogvl_wait_for_single_fd): nogvl_wait_for_single_fd must wait diff --git a/thread_win32.c b/thread_win32.c index d9a9bd1fd6..3d142701ad 100644 --- a/thread_win32.c +++ b/thread_win32.c @@ -165,53 +165,34 @@ Init_native_thread(void) 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) { HANDLE *targets = events; HANDLE intr; + const int initcount = count; DWORD ret; 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); ret = WaitForMultipleObjects(count, targets, FALSE, timeout); thread_debug(" WaitForMultipleObjects end (ret: %lu)\n", ret); - if (ret == (DWORD)(WAIT_OBJECT_0 + count - 1) && th) { + if (ret == (DWORD)(WAIT_OBJECT_0 + initcount) && th) { errno = EINTR; } if (ret == WAIT_FAILED && THREAD_DEBUG) { @@ -689,7 +670,9 @@ ubf_handle(void *ptr) 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 { diff --git a/version.h b/version.h index 33d2f8dab6..06c64d12aa 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.5" #define RUBY_RELEASE_DATE "2017-06-30" -#define RUBY_PATCHLEVEL 313 +#define RUBY_PATCHLEVEL 314 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 6 -- cgit v1.2.3