From 89c8ca32d0a8542c9360f45734c799d81c4738ad Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 30 Oct 2020 16:48:42 +0900 Subject: add a test of define_method with shareable Proc. a method defined by define_method with normal Proc can not cross ractors because the normal Proc is not shareable. However, shareable Proc can be crossed between ractors, so the method with shareable Proc should be called correctly. --- bootstraptest/test_ractor.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bootstraptest/test_ractor.rb') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index a61e741b54..65ea334bbb 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -933,6 +933,17 @@ assert_equal 'true', %q{ Ractor.shareable?(pr) } +# define_method() can invoke different Ractor's proc if the proc is shareable. +assert_equal '1', %q{ + class C + a = 1 + define_method "foo", Ractor.make_shareable(Proc.new{ a }) + a = 2 + end + + Ractor.new{ C.new.foo }.take +} + # Ractor.make_shareable(a_proc) makes a proc shareable. assert_equal 'can not make a Proc shareable because it accesses outer variables (a).', %q{ a = b = nil -- cgit v1.2.3