I create a thread in a function,and in another function,I wanna stop this thread. I have tried like this:
class Server
{
private:
boost::thread* mPtrThread;
...
public:
void createNewThread()
{
boost::thread t(...);
mPtrThread = &t;
}
void stopThread()
{
mPtrThread->interrupt();
}
}
But it's not work.How could I stop the thread?
If you want to use interrupt() you should define interruption points. Thread will be interrupted after calling interrupt() as soon as it reaches one of interruption points.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With