qdii
qdii

Reputation: 12963

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?

Upvotes: 3

Views: 526

Answers (1)

Pete Becker
Pete Becker

Reputation: 76245

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

Upvotes: 4

Related Questions