Including std::lock_guard in extra scope
问题 Does is make sense to do something like putting a std::lock_guard in an extra scope so that the locking period is as short as possible? Pseudo code: // all used variables beside the lock_guard are created and initialized somewhere else ...// do something { // open new scope std::lock_guard<std::mutex> lock(mut); shared_var = newValue; } // close the scope ... // do some other stuff (that might take longer) Are there more advantages besides having a short lock duration? What might be negative