diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-10-22 00:36:53 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-10-22 00:43:44 +0900 |
commit | 0c0d0752f1fefd9b085f191b62946a811763ef1b (patch) | |
tree | 17b70a64b83d53becde72478ecca76914285893e /bootstraptest | |
parent | 96293784779c000cdb5c07dd80be0dc208f8eeb9 (diff) |
allow to access ivars of frozen shareable objects
Accessing a shareable object is prohibitted because it can cause
race condition, but if the shareable object is frozen, there is no
problem to access ivars.
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ractor.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 6290b73c36..62b0b523ae 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -734,6 +734,18 @@ assert_equal 'can not access instance variables of shareable objects from non-ma end } +# But a sharable object is frozen, it is allowed to access ivars from non-main Ractor +assert_equal '11', %q{ + [Object.new, [], ].map{|obj| + obj.instance_variable_set('@a', 1) + Ractor.make_shareable obj = obj.freeze + + Ractor.new obj do |obj| + obj.instance_variable_get('@a') + end.take.to_s + }.join +} + # cvar in sharable-objects are not allowed to access from non-main Ractor assert_equal 'can not access class variables from non-main Ractors', %q{ class C |