#include <stdexcept>
#include <iostream>
#include <boost/coroutine/all.hpp>
using boost::coroutines::coroutine;
void cooperative(coroutine<void>::push_type &sink)
{
//返回main
sink();
throw std::runtime_error("error");
}
int main()
{
coroutine<void>::pull_type source{ cooperative };
try
{
//调用cooperative
source();
//捕获抛出的异常std::runtime_error
}
catch (const std::runtime_error &e)
{
std::cerr << e.what() << '\n';
}
}
c++协程4 (boost::coroutine)
最新推荐文章于 2024-03-22 09:40:13 发布