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

ruby-changes:66580

From: eileencodes <ko1@a...>
Date: Thu, 24 Jun 2021 02:03:24 +0900 (JST)
Subject: [ruby-changes:66580] 8209b73580 (master): Evacuate transient heap when enabling ractors

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

From 8209b735807d449c0a870562ee240585127ee100 Mon Sep 17 00:00:00 2001
From: eileencodes <eileencodes@g...>
Date: Tue, 22 Jun 2021 13:43:18 -0400
Subject: Evacuate transient heap when enabling ractors

If the GC has been disabled we need to re-enable it so we can evacuate
the transient heap.

Fixes https://bugs.ruby-lang.org/issues/17985

[Bug #17985] [ruby-core:104260]

Co-authored-by: Aaron Patterson <tenderlove@r...>
---
 bootstraptest/test_ractor.rb | 13 +++++++++++++
 ractor.c                     |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 7e77dfc..80591f6 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -1405,4 +1405,17 @@ assert_equal "ok", %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L1405
   end
 }
 
+assert_equal "ok", %q{
+  GC.disable
+  Ractor.new {}
+  raise "not ok" unless GC.disable
+
+  foo = []
+  10.times { foo << 1 }
+
+  GC.start
+
+  'ok'
+}
+
 end # if !ENV['GITHUB_WORKFLOW']
diff --git a/ractor.c b/ractor.c
index 372305c..b5835a8 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1420,9 +1420,15 @@ cancel_single_ractor_mode(void) https://github.com/ruby/ruby/blob/trunk/ractor.c#L1420
     // enable multi-ractor mode
     RUBY_DEBUG_LOG("enable multi-ractor mode", 0);
 
+    VALUE was_disabled = rb_gc_enable();
+
     rb_gc_start();
     rb_transient_heap_evacuate();
 
+    if (was_disabled) {
+        rb_gc_disable();
+    }
+
     ruby_single_main_ractor = NULL;
 
     if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_EXPERIMENTAL)) {
-- 
cgit v1.1


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

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