ruby-changes:64474
From: Delton <ko1@a...>
Date: Wed, 23 Dec 2020 03:27:37 +0900 (JST)
Subject: [ruby-changes:64474] c6d7e02b90 (master): Enable `Fiber.current` and `Fiber#alive?` call inside ractor
https://git.ruby-lang.org/ruby.git/commit/?id=c6d7e02b90 From c6d7e02b90f96d9bcd04edd48b7374f31c510b2a Mon Sep 17 00:00:00 2001 From: Delton Ding <dsh0416@g...> Date: Tue, 22 Dec 2020 15:30:59 +0900 Subject: Enable `Fiber.current` and `Fiber#alive?` call inside ractor diff --git a/cont.c b/cont.c index 123ca33..4a9e757 100644 --- a/cont.c +++ b/cont.c @@ -2744,6 +2744,9 @@ ruby_Init_Continuation_body(void) https://github.com/ruby/ruby/blob/trunk/cont.c#L2744 void ruby_Init_Fiber_as_Coroutine(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif rb_define_method(rb_cFiber, "transfer", rb_fiber_m_transfer, -1); rb_define_method(rb_cFiber, "alive?", rb_fiber_alive_p, 0); rb_define_singleton_method(rb_cFiber, "current", rb_fiber_s_current, 0); diff --git a/test/fiber/test_ractor.rb b/test/fiber/test_ractor.rb new file mode 100644 index 0000000..6d53b61 --- /dev/null +++ b/test/fiber/test_ractor.rb @@ -0,0 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/test/fiber/test_ractor.rb#L1 +# frozen_string_literal: true +require "test/unit" +require "fiber" + +class TestFiberCurrentRactor < Test::Unit::TestCase + def setup + skip unless defined? Ractor + end + + def test_ractor_shareable + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + require "fiber" + r = Ractor.new do + Fiber.new do + Fiber.current.class + end.resume + end + assert_equal(Fiber, r.take) + end; + end +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/