Ractor.yield should raise if out-port is closed
Ractor.yield should raise Ractor::ClosedError if current Ractor's outgoing-port is closed.
This commit is contained in:
parent
5286526346
commit
d247dedade
Notes:
git
2020-09-25 12:54:23 +09:00
@ -225,6 +225,27 @@ assert_equal 'ok', %q{
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Ractor.yield raises Ractor::ClosedError when outgoing port is closed.
|
||||||
|
assert_equal 'ok', %q{
|
||||||
|
r = Ractor.new Ractor.current do |main|
|
||||||
|
Ractor.recv
|
||||||
|
main << true
|
||||||
|
Ractor.yield 1
|
||||||
|
end
|
||||||
|
|
||||||
|
r.close_outgoing
|
||||||
|
r << true
|
||||||
|
Ractor.recv
|
||||||
|
|
||||||
|
begin
|
||||||
|
r.take
|
||||||
|
rescue Ractor::ClosedError
|
||||||
|
'ok'
|
||||||
|
else
|
||||||
|
'ng'
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
# Raise Ractor::ClosedError when try to send into a ractor with closed incoming port
|
# Raise Ractor::ClosedError when try to send into a ractor with closed incoming port
|
||||||
assert_equal 'ok', %q{
|
assert_equal 'ok', %q{
|
||||||
r = Ractor.new { Ractor.recv }
|
r = Ractor.new { Ractor.recv }
|
||||||
|
8
ractor.c
8
ractor.c
@ -832,6 +832,10 @@ ractor_try_yield(rb_execution_context_t *ec, rb_ractor_t *cr, struct rb_ractor_b
|
|||||||
ASSERT_ractor_unlocking(cr);
|
ASSERT_ractor_unlocking(cr);
|
||||||
VM_ASSERT(basket->type != basket_type_none);
|
VM_ASSERT(basket->type != basket_type_none);
|
||||||
|
|
||||||
|
if (cr->outgoing_port_closed) {
|
||||||
|
rb_raise(rb_eRactorClosedError, "The outgoing-port is already closed");
|
||||||
|
}
|
||||||
|
|
||||||
rb_ractor_t *r;
|
rb_ractor_t *r;
|
||||||
|
|
||||||
retry_shift:
|
retry_shift:
|
||||||
@ -1017,6 +1021,10 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield
|
|||||||
cr->wait.wakeup_status = wakeup_by_retry;
|
cr->wait.wakeup_status = wakeup_by_retry;
|
||||||
goto skip_sleep;
|
goto skip_sleep;
|
||||||
}
|
}
|
||||||
|
else if (cr->outgoing_port_closed) {
|
||||||
|
cr->wait.wakeup_status = wakeup_by_close;
|
||||||
|
goto skip_sleep;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user