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

ruby-changes:63382

From: Koichi <ko1@a...>
Date: Tue, 20 Oct 2020 15:39:51 +0900 (JST)
Subject: [ruby-changes:63382] ade411465d (master): ObjectSpace.each_object with Ractors

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

From ade411465dc054af5ff025531649b69134d74b56 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 20 Oct 2020 11:24:37 +0900
Subject: ObjectSpace.each_object with Ractors

Unshareable objects should not be touched from multiple ractors
so ObjectSpace.each_object should be restricted. On multi-ractor
mode, ObjectSpace.each_object only iterates shareable objects.
[Feature #17270]

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 9457059..a02adb6 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -823,6 +823,15 @@ assert_equal '[1, 4, 3, 2, 1]', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L823
   counts.inspect
 }
 
+# ObjectSpace.each_object can not handle unshareable objects with Ractors
+assert_equal '0', %q{
+  Ractor.new{
+    n = 0
+    ObjectSpace.each_object{|o| n += 1 unless Ractor.shareable?(o)}
+    n
+  }.take
+}
+
 ###
 ### Synchronization tests
 ###
diff --git a/gc.c b/gc.c
index 81d3bc2..f72d76e 100644
--- a/gc.c
+++ b/gc.c
@@ -3292,8 +3292,10 @@ os_obj_of_i(void *vstart, void *vend, size_t stride, void *data) https://github.com/ruby/ruby/blob/trunk/gc.c#L3292
 	volatile VALUE v = (VALUE)p;
 	if (!internal_object_p(v)) {
 	    if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
-		rb_yield(v);
-		oes->num++;
+                if (!rb_multi_ractor_p() || rb_ractor_shareable_p(v)) {
+                    rb_yield(v);
+                    oes->num++;
+                }
 	    }
 	}
     }
-- 
cgit v0.10.2


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

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