Sometimes it’s useful to reuse a std::thread object - from a resource and design point of view. This would seem trivial, but since the std::thread was designed as a single use object, there are a few tricks to reusing it.
Reusing a std::thread object would look something like this:
#include <thread>
void foo()
{
// do stuff...
}
void bar()
{
// do stuff...
}
//...
std::thread thObject (foo); //first use
//...
thObject = std::thread(bar); //reuse
So make sure you call join() on the thread object before reusing it.
This rule does not apply for detached threads.