diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-01-22 04:38:50 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-01-22 12:16:37 +0900 |
commit | fff1edf23ba28267bf57097c269f7fa87530e3fa (patch) | |
tree | b4e2d9bcf44aac5e3423d7d099805150cc979e94 /bootstraptest | |
parent | d0d6227a0da5925acf946a09191f172daf53baf2 (diff) | |
download | ruby-fff1edf23ba28267bf57097c269f7fa87530e3fa.tar.gz |
fix Ractor.yield(obj, move: true)
Ractor.yield(obj, move: true) and
Ractor.select(..., yield_value: obj, move: true) tried to yield a
value with move semantices, but if the trial is faild, the obj
should not become a moved object.
To keep this rule, `wait_moving` wait status is introduced.
New yield/take process:
(1) If a ractor tried to yield (move:true), make taking racotr's
wait status `wait_moving` and make a moved object by
`ractor_move(obj)` and wakeup taking ractor.
(2) If a ractor tried to take a message from a ractor waiting fo
yielding (move:true), wakeup the ractor and wait for (1).
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ractor.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 56add68403..0e3a6bce5d 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -709,6 +709,31 @@ assert_equal 'hello', %q{ end } +# yield/move should not make moved object when the yield is not succeeded +assert_equal '"str"', %q{ + R = Ractor.new{} + M = Ractor.current + r = Ractor.new do + s = 'str' + selected_r, v = Ractor.select R, yield_value: s, move: true + raise if selected_r != R # taken from R + M.send s.inspect # s should not be a moved object + end + + Ractor.receive +} + +# yield/move can fail +assert_equal "allocator undefined for Thread", %q{ + r = Ractor.new do + obj = Thread.new{} + Ractor.yield obj + rescue => e + e.message + end + r.take +} + # Access to global-variables are prohibited assert_equal 'can not access global variables $gv from non-main Ractors', %q{ $gv = 1 |