4 ms·
> lightweight cooperative concurrency It's not cooperative if multiple things happen _at the same time_ which is always touted of rust async. Cooperative would
by bruce343434 3y ago
> lightweight cooperative concurrency
It's not cooperative if multiple things happen _at the same time_ which is always touted of rust async. Cooperative would be iterators, or generators, or coroutines/continuations. They let you do things in a single thread but have the execution order be mixed. That's concurrent, but not parallel. What you are talking about is parallel execution. That changes the classification away from cooperative. Sorry, just a pet peeve of mine.
- rklaehn 3y agoIf you use rust async with a local executor such as the tokio current thread runtime, it provides lightweight cooperative concurrency. There is nothing ever happening at the same time, since you are on a single thread. That is why you don't need synchronization primitives such as Mutex but can live with something lightweight like RefCell. And that is why you can get by with non atomic reference counting smart pointers (Rc instead of Arc). And it is cooperative in that you have to yield by calling await, otherwise nothing else will run. What the article argues is that the option concurrent but not parallel, which both tokio and futures support in principle, should be advertised more and maybe even be the default.