3 ms·
Green threads, like Go has, is one good answer. You don't run around annotating what is and is not async. It just works. Even full OS threads are an acceptable
by jerf 5y ago
Green threads, like Go has, is one good answer. You don't run around annotating what is and is not async. It just works.
Even full OS threads are an acceptable answer for the vast majority of applications. It is good and proper for embedded programmers and OS designers and such to have options as powerful as Rust, but that does not mean the average program written in Rust is embedded, an OS, or needs to be able to scale to hundreds of thousands of threads.
(I actually think reaching straight for async/await is a mistake, personally. It's a tool for more extreme situations, not something you reach for when you're writing a program that's going to intermittently consume a fraction of a percent of CPU, or run a quick job where it may need maybe 10 threads if that and terminate. A lot of people badly overestimate the resources they need and jump straight for the extra-mega power tools for problems where they are literally a dozen orders of various magnitudes (CPU, RAM, etc.) away from needing them for their task.)
(It is extra ironic to be terrified of threads when working in a language like Rust that has so thoroughly tamed them!)
Yes, there are compromises, so you get the flip side of what I said above: Just because something has costs doesn't mean it doesn't have benefits. It is a benefit that you don't have to annotate everything yourself and the compiler and runtime just takes care of it.
"Remember that the point of async/await is cooperative threading and not pre-emption."
I disagree. Cooperative threading is a disaster. It doesn't scale. We tried it, very very hard, with an entire major consumer OS for decades. The point of async/await is precisely to get something like pre-emption into something that isn't using full, real threads (as its primary organization). That it functions like cooperative threading is one of the disadvantages that happens to be an acceptable compromise at most scales, not a goal.
- jayd16 5y ago>Cooperative threading is a disaster. It doesn't scale It doesn't need to scale because it solves a different problem. It find extreme success in UI and graphics programming where UI systems are dominated by a single UI thread for synchronization. GPU have been single threaded until recently. You can argue you do not like it but I can't see how you can argue against it's success. That said, I'm pretty interested to see a popular multithreaded/pre-emptive UI framework in the wild.