-
Hi guys! Great work with this Ruby implementation! I've stumbled upon this post talking about fibers in TruffleRuby. I'm creating a small language as an experiment and looking forward to implementing algebraic effects there. Having ability to suspend execution would really help here. Can you give me some pointers on how to achieve that? I'd very much apreciate any help since, I'm kindof stuck with it right now. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
TruffleRuby has support for the |
Beta Was this translation helpful? Give feedback.
-
Oh no, I guess I haven't been really clear. I'm implementing a language based on Truffle and wanted to leverage the continuations to implement algebraic effects. Problem I have is that I don't really know how to achieve this using Truffle. With TruffleRuby supporting Fibers this is probably achievable even without Project Loom, but I'm not sure how to do this. Do you have any hints? |
Beta Was this translation helpful? Give feedback.
-
Ahh. The best place to get started is to look at our FiberNodes. You'll be able to navigate to everything of note from there. If you have further questions, it's probably best to hop on the GraalVM Slack workspace and join the |
Beta Was this translation helpful? Give feedback.
-
Let's convert this to a discussion :) |
Beta Was this translation helpful? Give feedback.
-
So currently Fibers (= Ruby's stackful coroutines) are implemented using Threads and queues in TruffleRuby, to ensure only one execute at a time (per Ruby Thread). Regarding using them in Truffle, it's not different than using VirtualThread directly from regular Java, so I think you're mostly asking "what's the API of Loom" and that is Loom's API and that's mostly VirtualThread (e.g. docs https://download.java.net/java/early_access/loom/docs/api/java.base/java/lang/Thread.html). |
Beta Was this translation helpful? Give feedback.
So currently Fibers (= Ruby's stackful coroutines) are implemented using Threads and queues in TruffleRuby, to ensure only one execute at a time (per Ruby Thread).
I'm adding an option to use VirtualThread for Fibers on JDK 19+, but Truffle does not support them well yet, only in the DefaultTruffleRuntime currently.
Regarding using them in Truffle, it's not different than using VirtualThread directly from regular Java, so I think you're mostly asking "what's the API of Loom" and that is Loom's API and that's mostly VirtualThread (e.g. docs https://download.java.net/java/early_access/loom/docs/api/java.base/java/lang/Thread.html).
There is also a lower-level Continuation (https://github.co…