mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
Take VM lock in class_switch_superclass (#15356)
Safe multi-ractor subclass list mutation We need to lock around mutation and accesses of a class's subclasses list. Unfortunately we also need to do this when creating singleton classes, as the singleton class does need to go into `super`'s subclasses list for CC invalidation purposes.
This commit is contained in:
parent
d9aced864b
commit
de2c2bd60f
Notes:
git
2025-12-04 21:10:46 +00:00
Merged-By: luke-gru <luke.gru@gmail.com>
6
class.c
6
class.c
@ -734,8 +734,10 @@ class_detach_subclasses(VALUE klass, VALUE arg)
|
||||
static void
|
||||
class_switch_superclass(VALUE super, VALUE klass)
|
||||
{
|
||||
class_detach_subclasses(klass, Qnil);
|
||||
rb_class_subclass_add(super, klass);
|
||||
RB_VM_LOCKING() {
|
||||
class_detach_subclasses(klass, Qnil);
|
||||
rb_class_subclass_add(super, klass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -917,4 +917,17 @@ CODE
|
||||
end
|
||||
end;
|
||||
end
|
||||
|
||||
def test_safe_multi_ractor_subclasses_list_mutation
|
||||
assert_ractor "#{<<~"begin;"}\n#{<<~'end;'}"
|
||||
begin;
|
||||
4.times.map do
|
||||
Ractor.new do
|
||||
20_000.times do
|
||||
Object.new.singleton_class
|
||||
end
|
||||
end
|
||||
end.each(&:join)
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user