This commit is contained in:
Zengtudor 2025-07-16 22:28:43 +08:00
parent 4febfcb225
commit de75f61cd3

View File

@ -1,8 +1,5 @@
#include <cstdio>
#include <coroutine>
#include <ios>
#include <iostream>
#include <source_location>
#include <stdexcept>
#include <type_traits>
@ -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<int> test(){
int main(){
std::cout<<__FUNCTION__<<'\n';
auto handle = test();
while (!handle.done()) {
std::cout<<__FUNCTION__<<'\n';
while (!handle.done()) {
handle.resume();
std::cout<<__FUNCTION__<<'\n';
}
}