信息发布→ 登录 注册 退出

c++支持coroutine的简单示例

发布时间:2026-01-11

点击量:

平台:linux
依赖:g++ supports c++0x

复制代码 代码如下:
void func1()
{
    coroutine.yield();
}

void func2(Coro_t co1)
{
    coroutine.resume(co1);   
    coroutine.yield();
}

void func()
{
    Coro_t co1 = coroutine.create(std::bind(&func1));   
    coroutine.resume(co1);   
    Coro_t co2 = coroutine.create(std::bind(&func2, co1));
    coroutine.resume(co2);
    coroutine.resume(co2);
}

int main()
{   
    Coro_t co = coroutine.create(std::bind(&func));
    coroutine.resume(co);
    return 0;
}

标签:# span  # create  # std  # func  # resume  # bind  # main  # return  # int  # amp  # coroutine  # void  # supports  # linux  # BR  # Coro_t  # yield  # nbsp  # C++ Coroutine简单学习教程  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!