ruby-changes:63209
From: Samuel <ko1@a...>
Date: Wed, 30 Sep 2020 12:35:04 +0900 (JST)
Subject: [ruby-changes:63209] 388281c5c9 (master): Fix order of operations during `rb_ec_finalize`.
https://git.ruby-lang.org/ruby.git/commit/?id=388281c5c9 From 388281c5c92d4c04bfb08aeac7513770de9ea128 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Wed, 30 Sep 2020 15:24:36 +1300 Subject: Fix order of operations during `rb_ec_finalize`. diff --git a/eval.c b/eval.c index 43a5084..16f72d9 100644 --- a/eval.c +++ b/eval.c @@ -162,7 +162,11 @@ static void https://github.com/ruby/ruby/blob/trunk/eval.c#L162 rb_ec_scheduler_finalize(rb_execution_context_t *ec) { rb_thread_t *thread = rb_ec_thread_ptr(ec); - rb_thread_scheduler_set(thread->self, Qnil); + EC_PUSH_TAG(ec); + if (EC_EXEC_TAG() == TAG_NONE) { + rb_thread_scheduler_set(thread->self, Qnil); + } + EC_POP_TAG(); } static void @@ -217,6 +221,10 @@ rb_ec_cleanup(rb_execution_context_t *ec, volatile int ex) https://github.com/ruby/ruby/blob/trunk/eval.c#L221 rb_threadptr_interrupt(th); rb_threadptr_check_signal(th); + + // If the user code defined a scheduler for the top level thread, run it: + rb_ec_scheduler_finalize(ec); + EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { th = th0; @@ -278,9 +286,6 @@ rb_ec_cleanup(rb_execution_context_t *ec, volatile int ex) https://github.com/ruby/ruby/blob/trunk/eval.c#L286 } } - // If the user code defined a scheduler for the top level thread, run it: - rb_ec_scheduler_finalize(ec); - mjit_finish(true); // We still need ISeqs here. rb_ec_finalize(ec); diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb index 0e70585..23b59c0 100644 --- a/test/fiber/test_scheduler.rb +++ b/test/fiber/test_scheduler.rb @@ -35,4 +35,18 @@ class TestFiberScheduler < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_scheduler.rb#L35 thread.join end + + def test_close_at_exit + assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['Running Fiber'], [], success: true + require 'scheduler' + + scheduler = Scheduler.new + Thread.current.scheduler = scheduler + + Fiber.schedule do + sleep(0) + puts "Running Fiber" + end + RUBY + end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/