[前][次][番号順一覧][スレッド一覧]

ruby-changes:64429

From: Koichi <ko1@a...>
Date: Tue, 22 Dec 2020 05:54:33 +0900 (JST)
Subject: [ruby-changes:64429] d0e4ccbefc (master): add Ractor.main

https://git.ruby-lang.org/ruby.git/commit/?id=d0e4ccbefc

From d0e4ccbefcdd6032d0ae70bc54c9a4fb55d92576 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 22 Dec 2020 02:22:51 +0900
Subject: add Ractor.main

It returns main Ractor, like Thread.main.
[Feature #17418]

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 06bd739..843714a 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -396,6 +396,13 @@ assert_equal 'ok', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L396
   end
 }
 
+# Ractor.main returns main ractor
+assert_equal 'true', %q{
+  Ractor.new{
+    Ractor.main
+  }.take == Ractor.current
+}
+
 # a ractor with closed outgoing port should terminate
 assert_equal 'ok', %q{
   Ractor.new do
diff --git a/ractor.rb b/ractor.rb
index d72e02b..0a15242 100644
--- a/ractor.rb
+++ b/ractor.rb
@@ -768,4 +768,11 @@ class Ractor https://github.com/ruby/ruby/blob/trunk/ractor.rb#L768
   def []=(sym, val)
     Primitive.ractor_local_value_set(sym, val)
   end
+
+  # returns main ractor
+  def self.main
+    __builtin_cexpr! %q{
+      rb_ractor_self(GET_VM()->ractor.main_ractor);
+    }
+  end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]