summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2024-11-05 11:49:21 +0900
committerKoichi Sasada <ko1@atdot.net>2024-11-08 18:02:46 +0900
commit0d63b9b4a49d7477b5201f5d40ecd64916cd0e43 (patch)
tree1fbf7920bb34331284f2488a529ac6bcdf756c42
parent4886a54d74338c8a9c57312b51331296a2d506df (diff)
check closing flag
`Ractor.receive` and `Ractor.yield` should stop when the incoming/outgoing port is closed.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11142
-rw-r--r--ractor.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/ractor.c b/ractor.c
index 17a2248350..0b33340f11 100644
--- a/ractor.c
+++ b/ractor.c
@@ -753,7 +753,7 @@ ractor_wait_receive(rb_execution_context_t *ec, rb_ractor_t *cr, struct rb_racto
RACTOR_LOCK(cr);
{
- while (ractor_queue_empty_p(cr, rq)) {
+ while (ractor_queue_empty_p(cr, rq) && !cr->sync.incoming_port_closed) {
ractor_sleep(ec, cr, wait_receiving);
}
}
@@ -1364,6 +1364,9 @@ ractor_try_yield(rb_execution_context_t *ec, rb_ractor_t *cr, struct rb_ractor_q
return true;
}
+ else if (cr->sync.outgoing_port_closed) {
+ rb_raise(rb_eRactorClosedError, "The outgoing-port is already closed");
+ }
else {
RUBY_DEBUG_LOG("no take basket");
return false;
@@ -1375,7 +1378,7 @@ ractor_wait_yield(rb_execution_context_t *ec, rb_ractor_t *cr, struct rb_ractor_
{
RACTOR_LOCK_SELF(cr);
{
- while (!ractor_check_take_basket(cr, ts)) {
+ while (!ractor_check_take_basket(cr, ts) && !cr->sync.outgoing_port_closed) {
ractor_sleep(ec, cr, wait_yielding);
}
}