I got the captioned error in the mutex destructor. since the error may due to the mutex is in lock state during destruction, I create a new mutex class which is inherited from boost:mutex. it is to make sure the mutex is unlock during destruction. However, the same error still occurs. Any hits would be appreciated!
class CMutes : public boost::mutex
{
public:
CMutes()
{
};
virtual ~CMutes()
{
if (m_bLock)
boost::mutex::unlock();
};
void lock()
{
if(!m_bLock)
boost::mutex::lock();
else
cout << "Mutex is in lock state\n";
};
void unlock()
{
if (m_bLock)
boost::mutex::unlock();
else
cout << "Mutex is in unlock state\n";
}
boost::mutex& getMutex()
{
return *this;
}
private:
bool m_bLock;
};
EDIT: Yes you are right. I should use RAII. However, I am in a situation. I need to lock a resource before another thread is finish processing it. something like below.
Thread A:
void getDate()
{
m_oLock.lock();
// access resource
}
void unlock()
{
m_oLock.unlock();
}
Thread B:
void Process()
{
threadA.getData();
threadA.unlock();
}