Get ractor message passing working with > 1 thread sending/receiving values in same ractor

Rework ractors so that any ractor action (Ractor.receive, Ractor#send, Ractor.yield, Ractor#take,
Ractor.select) will operate on the thread that called the action. It will put that thread to sleep if
it's a blocking function and it needs to put it to sleep, and the awakening action (Ractor.yield,
Ractor#send) will wake up the blocked thread.

Before this change every blocking ractor action was associated with the ractor struct and its fields.
If a ractor called Ractor.receive, its wait status was wait_receiving, and when another ractor calls
r.send on it, it will look for that status in the ractor struct fields and wake it up. The problem was that
what if 2 threads call blocking ractor actions in the same ractor. Imagine if 1 thread has called Ractor.receive
and another r.take. Then, when a different ractor calls r.send on it, it doesn't know which ruby thread is associated
to which ractor action, so what ruby thread should it schedule? This change moves some fields onto the ruby thread
itself so that ruby threads are the ones that have ractor blocking statuses, and threads are then specifically scheduled
when unblocked.

Fixes [#17624]
Fixes [#21037]
This commit is contained in:
Luke Gruber 2025-05-12 18:03:22 -04:00 committed by Aaron Patterson
parent 2fee379f8f
commit 1d4822a175
Notes: git 2025-05-13 20:24:09 +00:00
8 changed files with 352 additions and 137 deletions

View file

@ -676,6 +676,7 @@ signal_ignored(int sig)
if (sigaction(sig, NULL, &old) < 0) return FALSE;
func = old.sa_handler;
#else
// TODO: this is not a thread-safe way to do it. Needs lock.
sighandler_t old = signal(sig, SIG_DFL);
signal(sig, old);
func = old;