As I understood, std::lock
locks section under its scope. But what if access to variable is performed in return
statement? Example:
// Looks safe...
bool foo
{
std::lock_guard<decltype(myMutex)> tLock(myMutex);
if (bar == 123)
{
return true;
}
else
{
return false;
}
}
// Is it safe?
bool foo
{
std::lock_guard<decltype(myMutex)> tLock(myMutex);
return bar == 123;
}