vendredi 24 janvier 2020

c++ std::packaged_task call throws system exception?

I've got a very simple code snippet from cpprefernce.com, as follows:

#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;
}

Once I run it with g++ on ubuntu18.04, it prints:

begin to call t
terminate called after throwing an instance of 'std::system_error'
what():  Unknown error -1
Aborted

So where does the program get wrong, how to fix it?

Aucun commentaire:

Enregistrer un commentaire