Why choose async/await over threads? | Hacker News
Multi-threaded async/await gets ugly. If you have serious compute-bound sections, the model tends to break down, because you're effectively blocking a thread that you share with others. Compute-bound multi-threaded does not work as well in Rust as it should. Problems include: - Futex congestion collapse. This tends to be a problem with some storage allocators. Many threads are hitting the same locks. In particular, growing a buffer can get very expensive in allocators where the recopying takes place with the entire storage allocator locked. I've mentioned before that Wine's library allocator, in a .DLL that's emulating a Microsoft library, is badly prone to this problem. Performance drops by two orders of magnitude with all the CPU time going into spinlocks. Microsoft's own implementation does not have this problem. - Starvation of unfair mutexes. Both the standard Mutex and crossbeam-channel channels are unfair. If you have multiple threads locking a resource, doing something, unlocki
Why choose async/await over threads? | Hacker News Hacker News new | past | comments | ask | show | jobs | submit login Why choose async/await over threads? ( notgull.net ) 430 points by thunderbong on March 25, 2024 | hide | past | favorite | 458 comments Animats on March 25, 2024 | next [–] Async/await with one thread is simple and well-understood. That's the Javascript model. Threads let you get all those CPUs working on the problem, and Rust helps you manage the locking. Plus, you can have threads at different priorities, which may be necessary if you're compute-bound. Multi
Explore this link on the map →related reading
- Async Rust Is A Bad Languagebitbashing.io
- Let futures be futureswithout.boats
- Concurrency Patterns in Embedded Rust - Ferrous Systemsferrous-systems.com
- async/await on embedded Rust - Ferrous Systemsferrous-systems.com
- What Async Promised and What it Delivered — Causalitycausality.blog
- Why async Rust?without.boats
- no_std async/await - soon on stable - Ferrous Systemsferrous-systems.com
- Reading 15: Promisesweb.mit.edu
- Fundamentals of Asynchronous Programming: Async, Await, Futures, and Streams - The Rust Programming Languagedoc.rust-lang.org
- Introduction - Asynchronous Programming in Rustrust-lang.github.io
- TypeScript Structured Concurrencythecandidstartup.org
- Using Threads to Run Code Simultaneously - The Rust Programming Languagedoc.rust-lang.org