ruby-changes:63479
From: Koichi <ko1@a...>
Date: Fri, 30 Oct 2020 16:52:39 +0900 (JST)
Subject: [ruby-changes:63479] 89c8ca32d0 (master): add a test of define_method with shareable Proc.
https://git.ruby-lang.org/ruby.git/commit/?id=89c8ca32d0 From 89c8ca32d0a8542c9360f45734c799d81c4738ad Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> 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. diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index a61e741..65ea334 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -933,6 +933,17 @@ assert_equal 'true', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L933 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 v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/