1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]
This commit is contained in:
Koichi Sasada 2020-10-20 11:24:37 +09:00
parent 2bdbdc1580
commit ade411465d
Notes: git 2020-10-20 15:40:00 +09:00
2 changed files with 13 additions and 2 deletions

View file

@ -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
###

6
gc.c
View file

@ -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++;
}
}
}
}