You create the scoped lock but then immediately destroy it, so it fails to protect your access to m_value
. You wanted this:
int GetValue() const
{
ScopedRWLock l(&m_rwlock);
return m_value;
}
Now, the lock remains in scope until m_value
is accessed.
Your probably also want to declare the lock mutable
so it can be accessed in const
member functions.