Is the mutex used in method GetValues()
released before or after copy constructing the dummy
instance?
class Protect
{};
class Test
{
public:
Protect GetValues() const;
private:
Protect m_protVal;
Mutex m_mutex;
};
Protect Test::GetValues() const
{
CLockGuard lock(m_mutex);
return m_protVal;
}
int main(int argc, char** argv)
{
Test myTestInstance;
Protect dummy = myTestInstance.GetValues();
}
Let's assume CLockGuard
and Mutex
are standard classes provided with boost lib.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…