2

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

Viktor
  • 1,004
  • 1
  • 10
  • 16

1 Answers1

4

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.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92