Reputation: 7232
I have a code that looks like:
boost::mutex::scoped_lock lck(mQueueMutex);
while (true)
{
...
// unlock the queue while we exec the job
lck.unlock();
...
// lock the queue again
lck.lock();
}
I am looking to do something like this:
boost::mutex::scoped_lock lock(mQueueMutex);
while (true)
{
...
// unlock the queue while we exec the job
{
boost::mutex::scoped_unlock unlock(lock);
...
}
}
I am almost sure that I have seen this before ... or at least discussion about it, but I can't find it.
Upvotes: 1
Views: 688
Reputation: 42544
You are looking for Boost.Threads Reverse Lock:
reverse_lock
reverse the operations of a lock: it provide for RAII-style, that unlocks the lock at construction time and lock it at destruction time. In addition, it transfer ownership temporarily, so that the mutex can not be locked using the Lock.
Upvotes: 4