首页 > 编程 > C++ > 正文

c++支持coroutine的简单示例

2020-01-26 15:34:38
字体:
来源:转载
供稿:网友

平台: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;
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表