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
Родитель 2bdbdc1580
Коммит ade411465d
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -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
Просмотреть файл

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