TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  OAL#018Checked automatically with code checker

Synopsis:Don't forget to give scoped locks a name
Language:C++
Severity Level:1
Category:Object Allocation


Description:

If you don't name a scoped lock, the lock will be set and released immediately. Take a look at the following code:

void EventListenerHelper::ClearEvents()
{
    boost::mutex::scoped_lock(m_mutex);
    m_events.clear();
}

The field "m_mutex" is locked and released immediately after that. It should have been something like

void EventListenerHelper::ClearEvents()
{
    boost::mutex::scoped_lock my_lock(m_mutex);
    m_events.clear();
}

instead. The scoped lock is now named "my_lock" and will remain "alive".