此处jobThread队列初始化后不会改变(因为没有实现自增长功能),所以非线程安全的vector队列即可,busthread的忙碌线程队列会被移进移出,但是操作会自带Lock sync( _tmutex),该互斥量是线程池本身继承的,所以是共有的,也无需另外使用线程安全的TC_ThreadQueue,使用vector即可。
TC_ThreadPool:: idle中的
- if( _busthread. empty()) {
- _bAllDone = true; _tmutex.notifyAll();
- }
主要用于当线程池工作起来后的waitForAllDone方法:
- bool TC_ThreadPool:: waitForAllDone( int millsecond) {
- Lock sync( _tmutex);
- start1: //任务队列和繁忙线程都是空的
- if (finish()) {
- return true; }
- //永远等待
- if(millsecond < 0) {
- _tmutex.timedWait(1000); goto start1;
- }
- int64_t iNow = TC_Common:: now2ms(); int m = millsecond;
- start2:
- bool b = _tmutex.timedWait(millsecond); //完成处理了
- if(finish()) {
- return true; }
- if(!b)
- { return false;
- }
- millsecond = max((int64_t )0, m - (TC_Common ::now2ms() - iNow)); goto start2;










