You are running a local thread inside a member function. You have to join it or detach it and, since it is local, you have to do this in the function itself:
exampleClass::runThreaded()
{
std::thread processThread(&exampleClass::completeProcess, this);
// more stuff
processThread.join();
} //
I am guessing what you really want is to launch a data member thread instead of launching a local one. If you do this, you still have to join it somewhere, for example in the destructor. In this case, your method should be
exampleClass::runThreaded()
{
processThread = std::thread(&exampleClass::completeProcess, this);
}
and the destructor
exampleClass::~exampleClass()
{
processThread.join();
}
and processThread
should be an std::thread
, not a pointer to one.
Just a note on design: if you are to have a runThreaded
method acting on a thread data member, you have to be very careful about not calling it more than once before the thread is joined. It might make more sense to launch the thread in the constructor and join it in the destructor.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…