Skip to content

Commit 1e3e0c7

Browse files
committed
Add a test that fails without these lock_rec changes.
1 parent d9e6507 commit 1e3e0c7

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

test/ruby/test_gc.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,4 +910,25 @@ def test_old_to_young_reference
910910
assert_include ObjectSpace.dump(young_obj), '"old":true'
911911
end
912912
end
913+
914+
def test_finalizer_not_run_with_vm_lock
915+
assert_ractor(<<~'RUBY')
916+
Thread.new do
917+
loop do
918+
Encoding.list.each do |enc|
919+
enc.names # takes VM Lock, can't have it held already
920+
end
921+
end
922+
end
923+
924+
o = Object.new
925+
ObjectSpace.define_finalizer(o, proc do
926+
sleep 0.5 # finalizer shouldn't be run with VM lock, otherwise this context switch will crash
927+
end)
928+
o = nil
929+
4.times do
930+
GC.start
931+
end
932+
RUBY
933+
end
913934
end

0 commit comments

Comments
 (0)