I am trying to add a std::function to std::thread and i stumble upon this error
error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues
struct Foo { explicit Foo(const std::function<void(int)>& tfunc) : thread(tfunc) { //<----- error points here thread.join(); } std::thread thread; }
Why is this not working?
Advertisement
Answer
The initial integer value is missing when thread ctor is called: thread(std::ref(tfunc), 123).
Function of thread body takes integer, you need to provide it when thread starts.