Std :: future exception in gcc experimental C ++ 0x implementation

I am experimenting with a C ++ 0x thread partially implemented in gcc 4.5, and I have a problem that I cannot understand. Let's take a look at this code

#include <future> #include <iostream> int main() { std::cout << std::async([]() { return 10; }).get() << std::endl; } 

it is quite simple and should work, but it is not. It throws std :: system_error

ending the call after calling the instance of 'std :: system_error' which (): Canceled

what () returns an empty string, so there is no error information. Moreover, he did not work on an online compiler that also uses gcc 4.5, but now it works. You can see it here http://liveworkspace.org/code/f3003d62a758e047a880920c84f1241c but yesterday he chose the same exception (although there were no changes on the server). Do you know what the problem is?

Thank.

+12
multithreading c ++ 11 g ++
Oct. 14 '10 at 6:39
source share
1 answer

Try linking to -lpthread. For some reason, the thread library compiles without pthreads, but it crashes at runtime.

+18
Oct. 14 '10 at 18:13
source share



All Articles