From db31ace934e8b900e90853bd875f23195837b398 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Tue, 10 Nov 2020 18:21:11 +0900 Subject: Threads in a ractor will be killed with the ractor If a terminating ractor has child threads, then kill all child threads. --- bootstraptest/test_ractor.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'bootstraptest/test_ractor.rb') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 527059d97b..86a033cba8 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -396,6 +396,39 @@ assert_equal '[RuntimeError, "ok", true]', %q{ end } +# threads in a ractor will killed +assert_equal '{:ok=>3}', %q{ + Ractor.new Ractor.current do |main| + q = Queue.new + Thread.new do + q << true + loop{} + ensure + main << :ok + end + + Thread.new do + q << true + while true + end + ensure + main << :ok + end + + Thread.new do + q << true + sleep 1 + ensure + main << :ok + end + + # wait for the start of all threads + 3.times{q.pop} + end + + 3.times.map{Ractor.receive}.tally +} + # unshareable object are copied assert_equal 'false', %q{ obj = 'str'.dup @@ -516,7 +549,6 @@ assert_equal [false, true, false].inspect, %q{ results << check(C.new(false).freeze) # false } - # move example2: String # touching moved object causes an error assert_equal 'hello world', %q{ -- cgit v1.2.3