instance method · added in Ruby 4.0
Fiber::Scheduler#fiber_interrupt
fiber_interrupt(fiber, exception)
scheduler.c
View on GitHub ↗
VALUE rb_fiber_scheduler_fiber_interrupt(VALUE scheduler, VALUE fiber, VALUE exception)
{
VALUE arguments[] = {
fiber, exception
};
VALUE result;
enum ruby_tag_type state;
// We must prevent interrupts while invoking the fiber_interrupt method, because otherwise fibers can be left permanently blocked if an interrupt occurs during the execution of user code. See also `rb_fiber_scheduler_unblock`.
rb_execution_context_t *ec = GET_EC();
int saved_interrupt_mask = ec->interrupt_mask;
ec->interrupt_mask |= PENDING_INTERRUPT_MASK;
EC_PUSH_TAG(ec);
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = rb_check_funcall(scheduler, id_fiber_interrupt, 2, arguments);
}
EC_POP_TAG();
ec->interrupt_mask = saved_interrupt_mask;
if (state) {
EC_JUMP_TAG(ec, state);
}
RUBY_VM_CHECK_INTS(ec);
return result;
}
Invoked by Ruby’s core methods to notify the scheduler that the blocked fiber should be interrupted with an exception. For example, IO#close uses this method to interrupt fibers that are performing blocking IO operations.
Ruby version changes
-
4.0
-
Introduce
Fiber::Scheduler#fiber_interruptto interrupt a fiber with a given exception. The initial use case is to interrupt a fiber that is waiting on a blockingIOoperation when theIOoperation is closed. [Feature #21166]
-