我不是 100% 确定你的意思,但你可以为std::lock_guard带花括号的引入一个块范围,如下所示:
void foo()
{
// do uncritical stuff
{
// critical part starts here with construction
std::lock_guard<std::mutex> myLock(someMutex);
// do critical stuff
} // critical parts end here with myLock going out of scope
// do uncritical stuff
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
224 次 |
| 最近记录: |