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

ruby-changes:64533

From: Koichi <ko1@a...>
Date: Thu, 24 Dec 2020 04:31:08 +0900 (JST)
Subject: [ruby-changes:64533] 7fcb6b3dbe (master): fix ractor-locking around rb_ractor_thread_list()

https://git.ruby-lang.org/ruby.git/commit/?id=7fcb6b3dbe

From 7fcb6b3dbe7517fe5426fdb6871cd4940a71b7e8 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 24 Dec 2020 04:18:17 +0900
Subject: fix ractor-locking around rb_ractor_thread_list()

With locking a ractor, rb_ary_push() can call RB_VM_LOCK_ENTER()
and it violates an assertion: should not acquire ractor-lock.

diff --git a/ractor.c b/ractor.c
index 585435c..26322f5 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1672,21 +1672,33 @@ rb_ractor_living_thread_num(const rb_ractor_t *r) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1672
 VALUE
 rb_ractor_thread_list(rb_ractor_t *r)
 {
-    VALUE ary = rb_ary_new();
     rb_thread_t *th = 0;
+    VALUE *ts;
+    int ts_cnt;
 
     RACTOR_LOCK(r);
-    list_for_each(&r->threads.set, th, lt_node) {
-        switch (th->status) {
-          case THREAD_RUNNABLE:
-          case THREAD_STOPPED:
-          case THREAD_STOPPED_FOREVER:
-            rb_ary_push(ary, th->self);
-          default:
-            break;
+    {
+        ts = ALLOCA_N(VALUE, r->threads.cnt);
+        ts_cnt = 0;
+
+        list_for_each(&r->threads.set, th, lt_node) {
+            switch (th->status) {
+              case THREAD_RUNNABLE:
+              case THREAD_STOPPED:
+              case THREAD_STOPPED_FOREVER:
+                ts[ts_cnt++] = th->self;
+              default:
+                break;
+            }
         }
     }
     RACTOR_UNLOCK(r);
+
+    VALUE ary = rb_ary_new();
+    for (int i=0; i<ts_cnt; i++) {
+        rb_ary_push(ary, ts[i]);
+    }
+
     return ary;
 }
 
-- 
cgit v0.10.2


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

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