Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Get ractor message passing working with > 1 thread sending and receiving values (WIP) #12633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025

Conversation

luke-gru
Copy link
Contributor

@luke-gru luke-gru commented Jan 24, 2025

A ractor can now have multiple threads calling r.take and r.send.

This is a WIP, comments welcome!
Windows builds that use thread_win32 are broken as expected. There's still some more work to get that working.

This comment has been minimized.

@luke-gru luke-gru force-pushed the ractor_take_multiple_threads branch from 4268e49 to 5bb1298 Compare January 24, 2025 21:22
@luke-gru luke-gru force-pushed the ractor_take_multiple_threads branch 8 times, most recently from 6fbbb5e to d07b796 Compare February 7, 2025 20:46
@luke-gru
Copy link
Contributor Author

luke-gru commented Feb 7, 2025

Windows is working now, but I can't get RJIT to work. I could have messed up somehow with rjit-bindgen

Edit: Nevermind, RJIT is currently failing for all builds. Also, Windows still has a bug with Visual Studio 2022.

@luke-gru luke-gru force-pushed the ractor_take_multiple_threads branch from d07b796 to 2b627bf Compare February 11, 2025 19:35
@luke-gru luke-gru force-pushed the ractor_take_multiple_threads branch 2 times, most recently from 552e667 to 325a1f4 Compare May 13, 2025 16:58
…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]
@luke-gru luke-gru force-pushed the ractor_take_multiple_threads branch from 325a1f4 to fa1735c Compare May 13, 2025 19:52
@tenderlove tenderlove enabled auto-merge (rebase) May 13, 2025 19:52
@tenderlove tenderlove merged commit 1d4822a into ruby:master May 13, 2025
79 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants