Are two code examples 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; }
- In the second example: will the lock go out of scope after a copy of the return value has been made? This would be important if an object were returned that had many copy instructions.
- Is locking required if you only return int? Or is it copying an int atomic operation?
c ++ multithreading mutex poco-libraries
Stackedcrooked
source share