gpt4 book ai didi

c++ - boost 互斥锁的作用域解锁

转载 作者:行者123 更新时间:2023-11-30 01:52:37 24 4
gpt4 key购买 nike

我的代码如下所示:

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);

...
}

}

我几乎可以肯定我以前见过这个……或者至少讨论过它,但我找不到它。

最佳答案

您正在寻找 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.

关于c++ - boost 互斥锁的作用域解锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24291504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com