我从cppreference.com获得了一个非常简单的代码片段,如下所示:
#include<future>
#include<iostream>
using namespace std;
int main(){
packaged_task<int(int)> t([](int i){return i+1;});
auto f = t.get_future();
cout<<"begin to call t\n";
t(3);
cout<<f.get()<<endl;
return 0;
}
一旦我在ubuntu18.04上使用g++运行它,它将打印:
begin to call t
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted