I am using a std::mutex
to copy a std::shared_ptr
at the beginning of a function.
// Lock the mutex
unique_lock<mutex> guard(d_mutex);
// Copy a shared_ptr
auto ptr = d_ptr;
// Unlock the mutex
guard.unlock();
// Operate with local ptr copy
During the operation, the guard remains associated with d_mutex
.
My question is: is there any reason to release()
the guard in addition to unlock()
ing it?