Is the mutex used in method GetValues() released before or after copy constructing the dummy instance?
Here is a small complete test programm (in addition to James Kanzes good explanation), which will show if the unlock is done before or after stack unwinding:
#include
class PseudoLockGuard
{
public:
enum LockState { IsStillLocked, IsUnlocked};
PseudoLockGuard(LockState& value) : m_value(value) {};
~PseudoLockGuard() { m_value = IsUnlocked; };
private:
LockState& m_value;
};
PseudoLockGuard::LockState Test()
{
PseudoLockGuard::LockState indicator = PseudoLockGuard::IsStillLocked;
PseudoLockGuard lock(indicator);
return indicator;// Will return IsStillLocked or IsUnlocked?
}
int main(int , char** )
{
PseudoLockGuard::LockState result = Test();
std::cout << (result == PseudoLockGuard::IsStillLocked
? "Return Value before Unlock"
: "Return Value after Unlock");
// Outputs "Return Value before Unlock"
return 0;
}