diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-19 05:52:18 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-19 05:52:18 +0900 |
commit | 80cb9165fa34185b601970da407a295a78ec9eff (patch) | |
tree | f19d3490ffb3fb4f5e68d02c0f551cf9d8fcbcc4 /bootstraptest | |
parent | cee02d754d76563635c1db90d2ab6c01f8492470 (diff) |
add "copy: true" option for Ractor.make_shareable
Ractor.make_shareable(obj) tries to make obj a shareable object
by changing the attribute of obj and traversable objects from obj
(mainly freeze them).
"copy: true" option is more conservative approach by make deep
copied object and make it sharable. It doesn't affect any existing
objects.
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ractor.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index e81afb6fa3..c587c2c1eb 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -1176,6 +1176,22 @@ assert_equal 'can not make a Proc shareable because it accesses outer variables end } +# Ractor.make_shareable(obj, copy: true) makes copied shareable object. +assert_equal '[false, false, true, true]', %q{ + r = [] + o1 = [1, 2, ["3"]] + + o2 = Ractor.make_shareable(o1, copy: true) + r << Ractor.shareable?(o1) # false + r << (o1.object_id == o2.object_id) # false + + o3 = Ractor.make_shareable(o1) + r << Ractor.shareable?(o1) # true + r << (o1.object_id == o3.object_id) # false + r +} + + # Ractor deep copies frozen objects (ary) assert_equal '[true, false]', %q{ Ractor.new([[]].freeze) { |ary| |