iterator循环的时候不能有删除操作,在循环中先查找,然后在循环外面删。
void CThreadPool::MoveToBusyList(CWorkerThread* idlethread)
{
m_IdleMutex.Lock();
m_BusyMutex.Lock();
m_BusyList.push_back(idlethread);
m_BusyMutex.Unlock();
for(ite=m_IdleList.begin();ite!=m_IdleList.end();ite++)
{
if(*ite==idlethread)
break;
}
m_IdleList.erase(ite);//就是这句
m_IdleMutex.Unlock();
}
void CThreadPool::MoveToIdleList(CWorkerThread* busythread)
{
m_BusyMutex.Lock();
m_IdleMutex.Lock();
m_IdleList.push_back(busythread);
m_IdleMutex.Unlock();
for(ite=m_BusyList.begin();ite!=m_BusyList.end();ite++)
{
if(*ite==busythread)
break;
}
m_BusyList.erase(ite);//就是这句
m_BusyMutex.Unlock();
m_IdleCond.Signal();
}