update
This commit is contained in:
parent
4febfcb225
commit
de75f61cd3
@ -1,8 +1,5 @@
|
||||
#include <cstdio>
|
||||
#include<coroutine>
|
||||
#include <ios>
|
||||
#include <coroutine>
|
||||
#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();
|
||||
std::cout<<__FUNCTION__<<'\n';
|
||||
while (!handle.done()) {
|
||||
std::cout<<__FUNCTION__<<'\n';
|
||||
handle.resume();
|
||||
std::cout<<__FUNCTION__<<'\n';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user