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' –