summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstraptest/test_ractor.rb9
-rw-r--r--gc.c6
2 files changed, 13 insertions, 2 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 94570597ba..a02adb612a 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -823,6 +823,15 @@ assert_equal '[1, 4, 3, 2, 1]', %q{
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 81d3bc2c27..f72d76e857 100644
--- a/gc.c
+++ b/gc.c
@@ -3292,8 +3292,10 @@ os_obj_of_i(void *vstart, void *vend, size_t stride, void *data)
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++;
+ }
}
}
}