News for hackers. Stuff that matters.
Re:Async Rust in Three Parts by vlovich123 on Thursday October 24, 2024 @05:15AM (#41933667)
Green threads can use more memory than async if you have a lot of I/O operations in flight since the stack is not precisely sized at pause points. Similarly, switching in new stacks is a bit more expensive than continuing a paused async task. Implementation details matter of course.
Re:Async Rust in Three Parts by palata on Thursday October 24, 2024 @09:58AM (#41935574)
Right, that's interesting. Still curious to know if that is "slightly better" or if that qualifies for the "tremendous advantage" mentioned above!
Re:Async Rust in Three Parts by vlovich123 on Thursday October 24, 2024 @11:45AM (#41936689)
It’s hard to say. If you want to use green threads, you may want to look at the may crate [1]. The reason Rust prioritized stackless async just like C++ did is that it fits better the systems programming needs (i.e. it’s syntactic sugar for a state machine you could hand implement) while not preventing things like stackful coroutines.

If Rust manages to solve the coloring problem of async (e.g. by adopting effect systems [2] or alternatives), then stackful and stackless coroutines syntactic sugar could conceivably exist within the std language (perhaps leaving out stackless on nostd).

The reason you don’t see both stackless and stackful coroutines in a single language like Rust is the coloring problem is made 50% worse.

[1] https://crates.io/crates/may

[2] https://blog.yoshuawuyts.com/extending-rusts-effect-system/

Re:Async Rust in Three Parts by steveklabnik on Thursday October 24, 2024 @11:48AM (#41936717)
Note that May has soundness issues that the authors handwave away. You can get UB in safe code while using it.
Re:Async Rust in Three Parts by vlovich123 on Thursday October 24, 2024 @01:35PM (#41937663)
You mean the TLS issue called out or something else?

I wasn't trying to recommend may specifically of course. Or are you saying that stackful coroutines must have soundness issues due to missing language features to make it safe?

Re:Async Rust in Three Parts by steveklabnik on Thursday October 24, 2024 @04:08PM (#41939220)
The TLS thing, yeah.

I am unsure if it's inherent to stackful coroutines or not, it's been a minute since I've dug into that.

Re:Async Rust in Three Parts by vlovich123 on Friday October 25, 2024 @02:43PM (#41948306)
Yeah, for TLS to work safely I suspect the only way would be language support which knows to media TLS through a "context pointer" so that the green threads could restore the context when resuming. In C++ the story is even worse because someone could take the address of a TLS variable & use it elsewhere. I think in general it's very very tricky to mix TLS and stackful coroutines that can be scheduled on arbitrary threads and languages like Go pick the stackful coroutines and drop the ability to do TLS.

To be fair though, I think people generally just avoid TLS when running with green thread systems.