Are the two code samples below equivalent?
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ProcessHandle::PID pid = 0;
mMutex.lock();
pid = mPID;
mMutex.unlock();
return pid;
}
,
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ScopedLock<Poco::Mutex> lock(mMutex);
return mPID;
}
They are equivalent. Locals don't go out of scope until after the last line of their block has been executed. So in this case, the return value copy is made under the protection of the lock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With