diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-10-30 16:48:42 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-10-30 16:52:09 +0900 |
commit | 89c8ca32d0a8542c9360f45734c799d81c4738ad (patch) | |
tree | 869918dad233fd763e2b2f6784e0ca23c418cc71 /bootstraptest/test_ractor.rb | |
parent | 08ddc335ea34829df756c164ceb13c56f0377d37 (diff) | |
download | ruby-89c8ca32d0a8542c9360f45734c799d81c4738ad.tar.gz |
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.
Diffstat (limited to 'bootstraptest/test_ractor.rb')
-rw-r--r-- | bootstraptest/test_ractor.rb | 11 |
1 files changed, 11 insertions, 0 deletions
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 |