Stream: beginners

Topic: Roc's threading model


view this post on Zulip Jan-Jan (Jun 07 2024 at 21:03):

Hi :wave: noob here.
Could someone please explain Roc's threading model to me? I couldn't find it the docs nor in any of the talks.

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 21:34):

Roc doesn't really have one

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 21:34):

It is up to the platform

view this post on Zulip Norbert Hajagos (Jun 08 2024 at 09:26):

There has been more discussion on this somewhere here in zulip. The Task as builtin proposal which will happen has points on this also.

view this post on Zulip Norbert Hajagos (Jun 08 2024 at 09:35):

(Correct me if I'm wrong pls) That would create a unified Roc api to ask for concurent execution of tasks from the platform (Roc could specify like: "when all 5 of these tasks are done (I don't care about the order), do this next task"). But yes, implementing it is still up to the platform, not up to Roc and the platform can choose to just execute those tasks on the same thread one after the other, so there is no guarantee they'll run in parallel.

view this post on Zulip Brendan Hansknecht (Jun 08 2024 at 17:33):

Yeah, roc can define a nice API, but that really doesn't say much about the underlying threading model. Technically speaking a platform could suspend roc execution at ever ! and move the roc application to a different core. Could theoretically even increment the refcount of everything in the task closure capture, store the state and have something to rewind back to.

view this post on Zulip Alexander Pyattaev (Jun 10 2024 at 18:28):

Arguably, roc platform could expose an API to spawn threads for bulk compute tasks (i.e. give it a closure, await for completion). Naturally, you would not be able to communicate with the thread while it is doing its thing, so it would be fairly limited. The most natural way to achieve threading that makes sense for real work would be to target something like Lunatic runtime which can emulate CSP for wasm binaries. Might be a fun thing to do as well, given that Lunatic is inspired to some extent by Erlang VM, it would be fitting to run a modern FP language on a modern version of bean VM=))

view this post on Zulip Alexander Pyattaev (Jun 10 2024 at 18:30):

More info here https://crates.io/crates/lunatic


Last updated: Jul 06 2025 at 12:14 UTC