我想创建范围锁,但我想要像:
{
if(lockRequired)
boost::mutex::scoped_lock(Mutex); //After this line we go out of scope
/* Here I also want to have Mutex */
}
Run Code Online (Sandbox Code Playgroud)
如果condition为true我想要锁定互斥锁但是在升级范围内.我知道我可以使用简单的.lock并且在范围结束时使用.unlock但是我有很多返回路径.我也可以在范围内创建一些SynchronizationGuard,并且whed析构函数被称为解锁互斥锁,但它不是干净的解决方案.一些建议?
最好的祝福.