iterator循环的时候不能有删除操作erase()

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();

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值