Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong usage of std::future?

I have nailed one of my bugs down to this little snippet, and yet I don’t understand why it doesn’t work.

#include <future>

int main()
{
    int ret = 0;

    std::future<int> parseSentence = std::async(std::launch::async, []() { return 3;} );
    ret = parseSentence.get();  

    return ret;
}

The code works, but helgrind finds a race condition happening. As the log was a bit long, I put it on a separate file that can be found here.

Anyone could tell me what I am doing wrong here?

like image 568
qdii Avatar asked May 18 '26 10:05

qdii


1 Answers

The code is correct, so if there's a race condition it's in the implementation of future or its companions.

like image 163
Pete Becker Avatar answered May 21 '26 00:05

Pete Becker