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

77 Views Asked by At

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++

1

There are 1 best solutions below

0
On BEST ANSWER

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.