From 5e421ce8d949a4f92568db359be0d188b66e58ca Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sun, 30 Mar 2025 19:18:34 +0200 Subject: ractor: don't inherit the default thread group [Bug #17506] `Thread.current.group` isn't shareable so it shouldn't be inherited by the main thread of a new Ractor. This cause an extra allocation when spawning a ractor, which could be elided with a bit of extra work, but not sure if it's worth the effort. --- test/ruby/test_ractor.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_ractor.rb b/test/ruby/test_ractor.rb index 5275768113..ec94df361f 100644 --- a/test/ruby/test_ractor.rb +++ b/test/ruby/test_ractor.rb @@ -60,6 +60,17 @@ class TestRactor < Test::Unit::TestCase assert_unshareable(x, "can not make shareable object for #", exception: Ractor::Error) end + def test_default_thread_group + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + Warning[:experimental] = false + + main_ractor_id = Thread.current.group.object_id + ractor_id = Ractor.new { Thread.current.group.object_id }.take + refute_equal main_ractor_id, ractor_id + end; + end + def assert_make_shareable(obj) refute Ractor.shareable?(obj), "object was already shareable" Ractor.make_shareable(obj) -- cgit v1.2.3