1
我有一个看起来像代码:提升作用域解锁互斥量
boost::mutex::scoped_lock lck(mQueueMutex);
while (true)
{
...
// unlock the queue while we exec the job
lck.unlock();
...
// lock the queue again
lck.lock();
}
我希望做这样的事情:
boost::mutex::scoped_lock lock(mQueueMutex);
while (true)
{
...
// unlock the queue while we exec the job
{
boost::mutex::scoped_unlock unlock(lock);
...
}
}
我几乎可以肯定在此之前,我已经看到了这一点......或至少是讨论它,但我找不到它。
你可能用两个作用域锁来重写代码,而忽略'scoped_unlock' –