News for hackers. Stuff that matters.
Re:Async Cancellation by pcwalton on Thursday November 11, 2021 @11:45PM (#29196385)
The way to make that work would be to make poll() unsafe and require async runtimes to uphold the invariant that poll() must be called until completion if Pending is ever returned. That way, runtimes would ensure memory safety.

This doesn't mean that functions using async/await would have to be unsafe, just functions that manually implement poll. I still don't love that, though.

Re:Async Cancellation by Arnavion on Friday November 12, 2021 @12:03AM (#29196448)
There's no way for an async runtime to do such a thing. An async runtime only knows about the top-level Future of each task. It knows nothing about what other Futures' poll()s the top-level Future's poll() calls in turn.

Async-await does not obviate this problem. `let (value, _) = futures::future::select(f1, f2).await.factor_first();` has the same problem, one of the futures is going to be dropped before it resolves.

Re:Async Cancellation by pcwalton on Friday November 12, 2021 @04:18AM (#29197539)
> It knows nothing about what other Futures' poll()s the top-level Future's poll() calls in turn.

That's why calling poll would be marked unsafe. When you call poll() manually it's on you to uphold the invariants.

> Async-await does not obviate this problem. `let (value, _) = futures::future::select(f1, f2).await.factor_first();` has the same problem, one of the futures is going to be dropped before it resolves.

Yes, you also need to reform select.

Matthias247 has done work to flesh out what this looks like: https://github.com/Matthias247/rfcs/pull/1

Re:Async Cancellation by Arnavion on Friday November 12, 2021 @02:45PM (#29203702)
>Matthias247 has done work to flesh out what this looks like: https://github.com/Matthias247/rfcs/pull/1

By making a new kind of async function that cannot be called from existing async functions, I see. I started reading it with the expectation that RTCFutures would automatically spawn() themselves to enforce the RTC requirement instead of introducing a third function color. I'm pessimistic a third function color will catch on, but let's see how it goes.