Error creating std::thread on Mac OS X with clang: "attempt to use a deleted function" Error creating std::thread on Mac OS X with clang: "attempt to use a deleted function" multithreading multithreading

Error creating std::thread on Mac OS X with clang: "attempt to use a deleted function"


    _th = std::thread(&Foo::threadFunc, *this);

This tries to make a copy of *this to store in the new thread object, but your type is not copyable because its member _th is not copyable.

You probably want to store a pointer to the object, not a copy of the object:

    _th = std::thread(&Foo::threadFunc, this);

N.B. your program will terminate because you do not join the thread. In your type's destructor you should do something like:

~Foo() { if (_th.joinable()) _th.join(); }