summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/thread.c b/thread.c
index b3b7a69..53bfbe8 100644
--- a/thread.c
+++ b/thread.c
@@ -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;