future::get() 抛出异常Unknown error -1

来源:互联网 发布:免费网站域名注册 编辑:程序博客网 时间:2024/05/22 17:05

系统:centos7

语言:c++

测试代码:a.cpp

#include <list>

#include <future>

using namespace std;

list<int> f(list<int> l)

{

return l;

}

int main()

{

list<int> l;

std::future<list<int> > fut(async(&f,move(l)));

fut.get();

return 0;

}

编译命令:g++  a.cpp

抛出异常原因:async启动了另一个线程,而编译时没有连接线程库。


修复方法:

编译命令改为:g++ a.cpp -lpthread

原创粉丝点击