gpt4 book ai didi

c++ - boost::scoped_lock 解锁

转载 作者:太空宇宙 更新时间:2023-11-04 14:34:32 31 4
gpt4 key购买 nike

我可以在超出 scoped_lock 范围之前解锁互斥锁吗?我怎么能那样做?

{boost::mutex::scoped_lock  lock(mutex);

if(conditionaA)
{
if(conditionB)
{
//could I unlock here as I don't want to hold the lock too long.
//perform calculation
}

}
else
{

}

}//lock scope

谢谢。

最佳答案

是的。

使用unlock() 方法。

{boost::mutex::scoped_lock  lock(mutex);

if(conditionaA)
{
if(conditionB)
{
//could I unlock here as I don't want to hold the lock too long.
lock.unlock(); // <--
}

//perform calculation

}
else
{

}

}//lock scope

关于c++ - boost::scoped_lock 解锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4655850/

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