zl程序教程

您现在的位置是:首页 >  后端

当前栏目

c++支持coroutine的简单示例

C++ 简单 示例 支持 coroutine
2023-06-13 09:15:19 时间

平台:linux
依赖:g++supportsc++0x

复制代码代码如下:


voidfunc1()
{
   coroutine.yield();
}

voidfunc2(Coro_tco1)
{
   coroutine.resume(co1);   
   coroutine.yield();
}

voidfunc()
{
   Coro_tco1=coroutine.create(std::bind(&func1));   
   coroutine.resume(co1);   
   Coro_tco2=coroutine.create(std::bind(&func2,co1));
   coroutine.resume(co2);
   coroutine.resume(co2);
}

intmain()
{   
   Coro_tco=coroutine.create(std::bind(&func));
   coroutine.resume(co);
   return0;
}