Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIGABRT when retrieving value from future

Tags:

c++

c++11

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;
}
like image 551
Juraj Blaho Avatar asked Mar 21 '26 10:03

Juraj Blaho


1 Answers

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

like image 68
Juraj Blaho Avatar answered Mar 24 '26 05:03

Juraj Blaho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!