4 Star 23 Fork 18

LearningOS/os-lectures

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
co.cpp 490 Bytes
一键复制 编辑 原始数据 按行查看 历史
Database Group of Tsinghua University 提交于 2023-05-16 09:37 . add
#include<stdio>
#include<coroutine>
coro_ret<int> number_generator(int begin, int count) {
std::cout << "number_generator invoked." << std::endl;
for (int i=begin; i<count; ++i) {
co_yield i;
}
co_return;
}
int main(int argc, char* argv[])
{
auto g = number_generator(1, 10);
std::cout << "begin to run!" << std::endl;
while(!g.resume()) {
std::cout << "got number:" << g.get() << std::endl;
}
std::cout << "coroutine done, return value:" << g.get() << std::endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/learning-os/os-lectures.git
git@gitee.com:learning-os/os-lectures.git
learning-os
os-lectures
os-lectures
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385