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.