Closed fredemmott closed 1 year ago
Does this also happen on 2.0.221121.5?
If y'all can point me to what's needed to get winrt coroutines working from
int main
without the framework, happy to give an isolated example
IAsyncOperation<int> Async() {
co_return 123;
}
int main() {
int result = Async().get();
printf("%ld\n", result);
}
Added isolated example, and yes, also happens on 2.0.221121.5
Briefly, you'll have to synchronize this yourself as the coroutine's completion doesn't assume the coroutine itself has been torn down. In fact, it's pretty much guaranteed to not be torn down. What with the coroutine type being reference counted, the stack frame holding a reference, and the caller holding a reference, there's just no guarantee that completion will be gated in this way. Coroutine cancellation is also quite lossy or wishful at best so that too is not something you should rely on.
Another way to think about it is that a WinRT coroutine is really just a COM object with all of the locals within the coroutine being members of the COM object. Naturally, the COM object is reference counted and thus has a lifetime of its own and you shouldn't count on it being destroyed as long as there is an outstanding reference, such as the coroutine stack frame (that may be waiting on some resource).
Hope that helps.
Version
2.0.230225.1
Summary
Not sure if bug or feature request :)
I have coroutines which use RAII to manage ownership of global exclusive resources (e.g. named shared Direct3D textures); occasionally I need to shut them down, then start them up again.
Ideally, I would write:
As a workaround, I'm doing:
... where I have storedAction calling
SetEvent()
via RAIIReproducible example
Expected behavior
co_await cancelled_iasyncaction
only completes when the coroutine has finished executingActual behavior
It appears to check that the IAsyncAction is marked as cancelled, then immediately returns without checking if it has actually finished executing
Additional comments
No response