-
Notifications
You must be signed in to change notification settings - Fork 13
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
求助 #4
Comments
co_await并没有“返回”的功能,一个协程结束后,要切换到哪个协程(相当于返回地址)是由final_suspend().await_suspend()的协程句柄决定的。 题外话,如果你要final_suspend()返回std::suspend_always()还能继续返回到hello里的话,main就要这样写: int main() {
world.resume();
hello.resume(); // world.resume() 遇到 std::suspend_always() 被退出了,需要main函数负责手动切换回调用者hello
} |
"接结束当前协程,返回到调用了world.resume()的main函数里去。" 这个里面返回到调用了 world.resume() 的地方去我知道,但是为啥是 main 函数中,我看main里面调用的是hello.resume |
说错了,是hello.resume。 |
对,我就是想问为啥会直接从 word 里面跳转到 hello.resume 而不是 hello 内部执行 |
return PreviousAwaiter(mPrevious) |
为什么要用return PreviousAwaiter(mPrevious)而不是mPrevious.resume()? |
也就是说编译器帮你resume 不算resume,只有手动resume 才算挂起点,所以返回最初的main里😘 |
我在 steps3.cpp 中将 40 行的 return PreviousAwaiter(mPrevious); 修改成了 return std::suspend_always(); 结果发现
world 协程 co_return 后没有返回到 hello 协成中的 co_await word() 处,按理 world 协成 co_return 完后应该会将控制权交还给之前 co_await 它的协成,求帮瞅瞅这里如何理解
auto final_suspend() noexcept {
// return PreviousAwaiter(mPrevious);
printf("%p exe final_suspend\n",std::coroutine_handle::from_promise(*this).address());
return std::suspend_always();
}
The text was updated successfully, but these errors were encountered: