A way to destroy “thread” class

前端 未结 8 1413
甜味超标
甜味超标 2021-02-06 18:22

Here is a skeleton of my thread class:

class MyThread {
public:
   virutal ~MyThread();

   // will start thread with svc() as thread entry point
   void start()         


        
8条回答
  •  我寻月下人不归
    2021-02-06 18:45

    You could havee somthing like this in your svc method

    while (alive){ //loops}
    //free resources after while.
    

    In your destructor, you could set the alive member to false. Or, you could have a pleaseDie() method, that sets the alive member to false, and can be called from the outside requesting the Thread instance to stop processing.

    void
    Thread::pleaseDie()
    {
    
     this->alive = false;
    }
    

提交回复
热议问题