代码之家  ›  专栏  ›  技术社区  ›  Troskyvs

C++ STD::PACGEDGED任务调用抛出系统异常?

  •  0
  • Troskyvs  · 技术社区  · 6 年前

    我从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
    

    0 回复  |  直到 6 年前