From f0d0c030c04c1c3949ac85a37b7d4bf8acebface Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Tue, 5 Nov 2024 03:57:48 +0900 Subject: [PATCH] `Ractor.main?` to return the current ractor is the main ractor. (== `Ractor.current == Ractor.main`) --- ractor.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ractor.rb b/ractor.rb index d18062ca07..6a83d3a92f 100644 --- a/ractor.rb +++ b/ractor.rb @@ -850,4 +850,11 @@ class Ractor rb_ractor_self(GET_VM()->ractor.main_ractor); } end + + # return true if the current ractor is main ractor + def self.main? + __builtin_cexpr! %q{ + GET_VM()->ractor.main_ractor == rb_ec_ractor_ptr(ec) + } + end end