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:
parent
2bdbdc1580
commit
ade411465d
Notes:
git
2020-10-20 15:40:00 +09:00
@ -823,6 +823,15 @@ assert_equal '[1, 4, 3, 2, 1]', %q{
|
|||||||
counts.inspect
|
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
|
### Synchronization tests
|
||||||
###
|
###
|
||||||
|
6
gc.c
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;
|
volatile VALUE v = (VALUE)p;
|
||||||
if (!internal_object_p(v)) {
|
if (!internal_object_p(v)) {
|
||||||
if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
|
if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
|
||||||
rb_yield(v);
|
if (!rb_multi_ractor_p() || rb_ractor_shareable_p(v)) {
|
||||||
oes->num++;
|
rb_yield(v);
|
||||||
|
oes->num++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user