深入解析C++编程中线程池的使用

2020-01-06 14:01:59于海丽
  • *   * @param ptw 
  • */  void idle(ThreadWorker *ptw); 
  •   /** 
  • * @brief 通知等待在任务队列上的工作线程醒来  */ 
  • void notifyT();   
  • /**  * @brief 是否处理结束. 
  • *  * @return bool 
  • */  bool finish(); 
  •   /** 
  • * @brief 线程退出时调用  */ 
  • void exit();   
  • friend class ThreadWorker;  protected: 
  •   /** 
  • * 任务队列  */ 
  • TC_ThreadQueue< TC_FunctorWrapperInterface*> _jobqueue;   
  • /**  * 启动任务 
  • */  TC_ThreadQueue< TC_FunctorWrapperInterface*> _startqueue; 
  •   /** 
  • * 工作线程  */ 
  • std::vector<ThreadWorker *> _jobthread;   
  • /**  * 繁忙线程 
  • */  std::set<ThreadWorker *> _busthread; 
  •   /** 
  • * 任务队列的锁  */ 
  • TC_ThreadLock _tmutex;   
  • /**  * 是否所有任务都执行完毕 
  • */  bool _bAllDone; 
  • }; 

    工作线程设计如下:

     

     
    1. TC_ThreadPool ::ThreadWorker::ThreadWorker(TC_ThreadPool *tpool)  : _tpool (tpool)