diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-20 11:34:02 +1200 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-21 09:51:33 +1200 |
commit | 501fff14c7657f769d68f90de98fd2ebccb807fb (patch) | |
tree | 10dfcaf36b27dcd6b83268f9b0de2516fed41ec2 /thread.c | |
parent | b6d599d76ec85422bea16b63f105985cf08e04bd (diff) | |
download | ruby-501fff14c7657f769d68f90de98fd2ebccb807fb.tar.gz |
When setting current thread scheduler to nil, invoke `#close`.
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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; |