mardi 10 mars 2015

Run Time Errors with C++ 2011 Threads

I have the following simple program using the thread library of C++11. It compiles but does not run.



#include <iostream>
#include <future>
using namespace std;
double square(int i) {
return i * i;
}

int main() {
future<double> fd = async(square, 2);
double d = fd.get();
cout << d << endl;
return 0;
}


Runnning the program gives



terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)


I use gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) and compile with "g++ -o main3 -std=c++11 -Wall -g main3.cpp -lpthread" Has anybody a good idea what's happening there?


Aucun commentaire:

Enregistrer un commentaire