aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-20 11:34:02 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-21 09:51:33 +1200
commit501fff14c7657f769d68f90de98fd2ebccb807fb (patch)
tree10dfcaf36b27dcd6b83268f9b0de2516fed41ec2 /thread.c
parentb6d599d76ec85422bea16b63f105985cf08e04bd (diff)
downloadruby-501fff14c7657f769d68f90de98fd2ebccb807fb.tar.gz
When setting current thread scheduler to nil, invoke `#close`.
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 b3b7a69305..53bfbe8562 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;