3

I have a problem using C++11 futures. When I call wait() or get() on the future returned by std::async, the program receives SIGABRT signal thrown from the mutex header. What could be the problem? How to fix it?

I use g++ 4.6 on Linux. Pasting the following code to ideone.com causes the same problem.

#include <future>
#include <thread>

int calculate() {
    return 1;
}

int main() {
    auto result = std::async(calculate);
    result.wait();// <-- this aborts
    int value = result.get();// <-- or this aborts as well if previous line is commented out.

    return 0;
}
Juraj Blaho
  • 13,301
  • 7
  • 50
  • 96
  • 1
    maybe take a look at this: http://stackoverflow.com/questions/4426141/asynchronous-function-call-c0x – AndersK Nov 01 '11 at 14:20
  • @Anders K.: That does not seem to be of any use here. I would be satisfied with the default launch policy if it didn't crash. – Juraj Blaho Nov 01 '11 at 14:26

1 Answers1

2

The problem may be solved by adding -pthread switch to g++.

Juraj Blaho
  • 13,301
  • 7
  • 50
  • 96