问题描述
我想恢复跨线程的 boost 纤维。不幸的是,我在 boost 光纤文档中找不到任何有用的东西,即使在“在线程之间迁移光纤”段落也是如此。
示例代码:
#include <iostream>
#include <future>
#include <boost/fiber/all.hpp>
#include <chrono>
int main()
{
boost::fibers::fiber myfiber{[]()
{
while(true) { // Long running fiber
std::cerr << std::this_thread::get_id() << std::endl;
boost::this_fiber::sleep_for(std::chrono::seconds{1});
}
}};
// myfiber.detach();
while(true) { // long life app main loop
std::this_thread::sleep_for(std::chrono::seconds{1});
auto fut = std::async(std::launch::async,[&myfiber]()
{
//***-> myfiber.attach();
boost::this_fiber::yield(); // resume myfiber from this thread
// myfiber.detach();
});
fut.get();
}
myfiber.join();
}
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)