Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop/interrupt a boost::thread?

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?

like image 263
wtm Avatar asked May 10 '12 10:05

wtm


1 Answers

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.

like image 155
Aligus Avatar answered Sep 29 '22 17:09

Aligus