Viktor
Viktor

Reputation: 1054

Why does std::package_task fails to be called on GCC

Following code is ok on Microsoft and Clang compilers but fails on GCC. It throws std::system_error with message -1. Is it know issue?

#include <future>

int main() 
{
    std::packaged_task<void()> task([](){});
    task();
}

GCC

Clang

Visual C++

Upvotes: 2

Views: 69

Answers (1)

Florian Weimer
Florian Weimer

Reputation: 33719

You need to link with -lpthread, otherwise there is no thread support the C++ run-time library could use. This has been reported as a GCC bug:

I agree that the usability here is quite poor. There is also a previous discussion.

Upvotes: 4

Related Questions