When setting current thread scheduler to nil, invoke #close.

This commit is contained in:
Samuel Williams 2020-09-20 11:34:02 +12:00
parent b6d599d76e
commit 501fff14c7
Notes: git 2020-09-21 06:52:08 +09:00
7 changed files with 75 additions and 6 deletions

View file

@ -748,10 +748,7 @@ thread_do_start(rb_thread_t *th)
rb_bug("unreachable");
}
VALUE scheduler = th->scheduler;
if (scheduler != Qnil) {
rb_funcall(scheduler, rb_intern("run"), 0);
}
rb_thread_scheduler_set(th->self, Qnil);
}
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
@ -3732,6 +3729,11 @@ rb_thread_scheduler_set(VALUE thread, VALUE scheduler)
VM_ASSERT(th);
// We invoke Scheduler#close when setting it to something else, to ensure the previous scheduler runs to completion before changing the scheduler. That way, we do not need to consider interactions, e.g., of a Fiber from the previous scheduler with the new scheduler.
if (th->scheduler != Qnil) {
rb_scheduler_close(th->scheduler);
}
th->scheduler = scheduler;
return th->scheduler;