boost :: scoped_lock解锁

Ash*_*ley 0 c++ boost

我可以在超出scoped_lock范围之前解锁互斥锁吗?我怎么能这样做?

{boost::mutex::scoped_lock  lock(mutex);

if(conditionaA)
{
   if(conditionB)
   {
    //could I unlock here as I don't want to hold the lock too long.
    //perform calculation
   }

}
else
{

}

}//lock scope
Run Code Online (Sandbox Code Playgroud)

谢谢.

Kaz*_*gon 16

是.

使用该unlock()方法.

{boost::mutex::scoped_lock  lock(mutex);

if(conditionaA)
{
   if(conditionB)
   {
    //could I unlock here as I don't want to hold the lock too long.
    lock.unlock(); // <--
   }

   //perform calculation

}
else
{

}

}//lock scope
Run Code Online (Sandbox Code Playgroud)


tem*_*def 6

是; 只需使用.unlock()成员函数.