Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::promise<T>::set_value() on Ubuntu 13.10 ends with "unknown error -1" (std::system_error)

The following cpp code doesn't run on Ubuntu 13.10 using g++-4.8 or g++-4.7. I have no idea how to solve that issue. It seems that on older Ubuntu versions (e.g. 13.04) the code below works fine.

Code

#include <future>
#include <iostream>

int main(int argc, char** argv) 
{
    int step = 0;
    std::cout << "step " << ++step << std::endl;

    std::promise<int> promise;
    std::cout << "step " << ++step << std::endl;

    try
    {
        promise.set_value(42);
        std::cout << "step " << ++step << std::endl;
    }
    catch (const std::system_error& ex)
    {
        std::cout << "Exception: " << ex.what() << "\n";
    }
}

Build And Run

g++ promise_test.cpp -o promise_test -pthread -std=c++11 && ./promise_test

Output

step 1
step 2
Exception: Unknown error -1
like image 635
Tobias Weibel Avatar asked Jan 21 '26 05:01

Tobias Weibel


2 Answers

The bug report. The work around provided is -Wl,--no-as-needed. See this other question.

As an alternative we fixed it with -static-libstdc++ flag.

like image 33
Lars Schneider Avatar answered Jan 23 '26 19:01

Lars Schneider



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!