-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
out of order destruction #61
Comments
@Spongman I'm quite certain that this behaviour is as expected with the following reasoning:
|
Yeah, i figured it had something to do with the lifetime of the coroutine. i'm not familiar with the internal details, but it does seem to me like the frame should be deleted before the callback is invoked. Here's another example that illustrates this independent of the way it's invoked: cti::coroutine<> inner() | void inner()
{ | {
Foo local; | Foo local;
co_return; | return;
} | }
|
cti::coroutine<> outer() | void outer()
{ | {
co_await inner(); | inner();
cerr << "inner done\n"; | cerr << "inner done\n";
co_return; | return;
} | } In the synchronous version on the right, obviously However, in the async version on the left, Regardless of the internal implementation, that just doesn't seem right to me: it means the scope rules of RAII are essentially broken in coroutines. |
Ok, I totally agree with you now. I'm not sure if this is easy to fix, since in general it is not explicitly specified by the library design when the destruction of the outer continuation occurs after it was used. |
@Naios
I'm not sure if this is an issue with the continuable lib, or if I'm doing something wrong, or if I just funamentally don't understand how coroutines are supposed to work...
The issue is that the destructor for a local object in a coroutine is getting called after the
co_return
has 'returned' control to the caller:https://gcc.godbolt.org/z/cT7rv93hP
this outputs:
i would expect that last two lines to be swapped, as it would be if this were a normal synchronous function.
maybe I'm managing the lifetime of the future incorrectly? or that just the way it's supposed to work with coroutines?
Commit Hash
master
(plus my clang fix)The text was updated successfully, but these errors were encountered: