From de75f61cd37e2df73d5b8f65f55dd48d21f933c6 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Wed, 16 Jul 2025 22:28:43 +0800 Subject: [PATCH] update --- src/test1.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test1.cpp b/src/test1.cpp index aa2849f..da76d50 100644 --- a/src/test1.cpp +++ b/src/test1.cpp @@ -1,8 +1,5 @@ -#include -#include -#include +#include #include -#include #include #include @@ -19,8 +16,9 @@ struct Promise{ auto initial_suspend(){ std::cout<<__FUNCTION__<<'\n'; return std::suspend_always{}; + // return std::suspend_never{}; } - auto final_suspend()noexcept{ + auto final_suspend()noexcept{//最后要不要把句柄执行权限归还,如果不归还,那么协程被销毁,继续检查.done()则Segmentation fault std::cout<<__FUNCTION__<<'\n'; return std::suspend_always{}; } @@ -53,8 +51,9 @@ coroutine test(){ int main(){ std::cout<<__FUNCTION__<<'\n'; auto handle = test(); + std::cout<<__FUNCTION__<<'\n'; while (!handle.done()) { - std::cout<<__FUNCTION__<<'\n'; handle.resume(); + std::cout<<__FUNCTION__<<'\n'; } } \ No newline at end of file