News for hackers. Stuff that matters.
Re:How to think about `async`/`await` in Rust by wruza on Wednesday July 05, 2023 @03:26AM (#36596848)
To me, async is just "cooperative multitasking" with a quick paintjob

It is, and not only to you. It is a way to save a call stack until a runloop calls it back.

But what I can’t agree with is parallels with OS. Coop MT is only problematic in OS MT. When it’s your code there’s no unknown bad actor, and having multiple cooperative (mostly waiting) processes without scheduling them on a thread pool is a useful concept regardless of threads availability.

E.g. when you have to wait on multiple sources, the options you have are:

- serialize

- perform few non-blocking calls and wait for any/all of them to complete

- schedule them as tasks on a thread pool and wait for their completion

Async can do all three, it’s orthogonal. I’d say that just awaiting on PMT task completion is much more convenient that setting up locking primitives. Same for NB polling. Promise is just an abstraction and all it does is waiting for an event to fire on a current thread’s runloop while retaining the comfort of a lexical scope, all with a couple of keywords.

Re:How to think about `async`/`await` in Rust by hayley-patton on Wednesday July 05, 2023 @04:52AM (#36597636)
But I'm my own worst enemy, and blocking the event loop is unpleasant even when I do it myself. Once I had to pass compute-intensive tasks (hashing some data, which took long enough to matter) to a thread pool, to not hurt latency for other tasks in the event loop.

> I’d say that just awaiting on PMT task completion is much more convenient that setting up locking primitives.

Don't use the primitives then - write e.g. a parbegin/parallel-map atop thread primitives, and use that.

Re:How to think about `async`/`await` in Rust by amelius on Wednesday July 05, 2023 @05:44AM (#36598025)
Async is great for dealing with I/O but it forgets that the CPU is a resource too.
Re:How to think about `async`/`await` in Rust by Spivak on Wednesday July 05, 2023 @02:18PM (#36604726)
Which is why you queue up CPU intensive tasks to threads where you can time slice, and IO intensive tasks to async/fibers whatever you wanna call them. It's hard to make this completely seamless. Power to Java for getting the closest.