Use atomic for method reference count [Bug #20934]

This changes reference_count on rb_method_definition_struct into an
atomic.

Ractors can create additional references as part of `bind_call` or
(presumably) similar. Because this can be done inside Ractors, we should
use a lock or atomics so that we don't race and avoid incrementing.

Co-authored-by: wanabe <s.wanabe@gmail.com>
This commit is contained in:
John Hawthorn 2025-03-18 15:02:44 -07:00
parent 62cc3464d9
commit bfe6068417
Notes: git 2025-03-20 20:09:57 +00:00
3 changed files with 29 additions and 11 deletions

View file

@ -1937,3 +1937,16 @@ assert_equal 'LoadError', %q{
end
r.take
}
# bind_call in Ractor [Bug #20934]
assert_equal 'ok', %q{
2.times.map do
Ractor.new do
1000.times do
Object.instance_method(:itself).bind_call(self)
end
end
end.each(&:take)
GC.start
:ok.itself
}