diff --git a/ractor.c b/ractor.c index 18263d2b8d..0ad13733c8 100644 --- a/ractor.c +++ b/ractor.c @@ -877,6 +877,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield VALUE crv = cr->self; VALUE ret = Qundef; int i; + bool interrupted = false; enum ractor_wait_status wait_status = 0; bool yield_p = (yielded_value != Qundef) ? true : false; @@ -914,6 +915,8 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield } rs = NULL; + restart: + if (yield_p) { actions[i].type = ractor_select_action_yield; actions[i].v = Qundef; @@ -1079,6 +1082,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield break; case wakeup_by_interrupt: ret = Qundef; + interrupted = true; goto cleanup; } } @@ -1095,7 +1099,11 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield VM_ASSERT(cr->wait.taken_basket.type == basket_type_none); VM_ASSERT(cr->wait.yielded_basket.type == basket_type_none); - RUBY_VM_CHECK_INTS(ec); + if (interrupted) { + rb_vm_check_ints_blocking(ec); + interrupted = false; + goto restart; + } VM_ASSERT(ret != Qundef); return ret; diff --git a/thread.c b/thread.c index ab574e5c29..6b20716245 100644 --- a/thread.c +++ b/thread.c @@ -218,6 +218,12 @@ vm_check_ints_blocking(rb_execution_context_t *ec) return rb_threadptr_execute_interrupts(th, 1); } +int +rb_vm_check_ints_blocking(rb_execution_context_t *ec) +{ + return vm_check_ints_blocking(ec); +} + /* * poll() is supported by many OSes, but so far Linux is the only * one we know of that supports using poll() in all places select() diff --git a/vm_core.h b/vm_core.h index 70714420f2..1d869617b6 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1836,6 +1836,7 @@ void rb_execution_context_update(const rb_execution_context_t *ec); void rb_execution_context_mark(const rb_execution_context_t *ec); void rb_fiber_close(rb_fiber_t *fib); void Init_native_thread(rb_thread_t *th); +int rb_vm_check_ints_blocking(rb_execution_context_t *ec); #define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec) static inline void