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

ruby-changes:65123

From: Koichi <ko1@a...>
Date: Wed, 3 Feb 2021 08:53:25 +0900 (JST)
Subject: [ruby-changes:65123] 6f727853ce (master): only main thread can modify vm->ubf_async_safe

https://git.ruby-lang.org/ruby.git/commit/?id=6f727853ce

From 6f727853cee41195b67ee5d793c1ac23fe1a6ae0 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Wed, 3 Feb 2021 03:19:51 +0900
Subject: only main thread can modify vm->ubf_async_safe

vm->ubf_async_safe is VM global resource and only main thread
can manipulate it.
[Bug #17482]
---
 thread.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/thread.c b/thread.c
index dce181d..f1d8c9a 100644
--- a/thread.c
+++ b/thread.c
@@ -1650,6 +1650,8 @@ rb_nogvl(void *(*func)(void *), void *data1, https://github.com/ruby/ruby/blob/trunk/thread.c#L1650
     void *val = 0;
     rb_execution_context_t *ec = GET_EC();
     rb_thread_t *th = rb_ec_thread_ptr(ec);
+    rb_vm_t *vm = rb_ec_vm_ptr(ec);
+    bool is_main_thread = vm->ractor.main_thread == th;
     int saved_errno = 0;
     VALUE ubf_th = Qfalse;
 
@@ -1658,8 +1660,8 @@ rb_nogvl(void *(*func)(void *), void *data1, https://github.com/ruby/ruby/blob/trunk/thread.c#L1660
 	data2 = th;
     }
     else if (ubf && rb_ractor_living_thread_num(th->ractor) == 1) {
-        if (flags & RB_NOGVL_UBF_ASYNC_SAFE) {
-            th->vm->ubf_async_safe = 1;
+        if (is_main_thread && flags & RB_NOGVL_UBF_ASYNC_SAFE) {
+            vm->ubf_async_safe = 1;
         }
         else {
             ubf_th = rb_thread_start_unblock_thread();
@@ -1671,7 +1673,7 @@ rb_nogvl(void *(*func)(void *), void *data1, https://github.com/ruby/ruby/blob/trunk/thread.c#L1673
 	saved_errno = errno;
     }, ubf, data2, flags & RB_NOGVL_INTR_FAIL);
 
-    th->vm->ubf_async_safe = 0;
+    if (is_main_thread) vm->ubf_async_safe = 0;
 
     if ((flags & RB_NOGVL_INTR_FAIL) == 0) {
 	RUBY_VM_CHECK_INTS_BLOCKING(ec);
-- 
cgit v1.1


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

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