Link to home
Start Free TrialLog in
Avatar of zube
zube

asked on

CSingleLock Debug Assertion

I added a CMutex object to some code I was writing. Occasionaly I get a Debug assertion on the
ASSERT(!m_bAcquired)  in the CSingleLock::Lock() m_bAcquired is 0 when the error occurs and the class looks like everything is in order.

This happens intermittantly and sometimes clears up after a full rebuild. The assertion does not crash the program, if I click "ignore" it seems to function fine. The assertion always occers when called from the same function. The calls to Lock from other functions in the class work fine.

I HAVE verified that I am not forgetting to Unlock the Mutex.

A basic idea of what I'm doing...

myclass::myclass()
{
        cmutex = new CMutex();
      singlelock = new CSingleLock(cmutex);
}

myclass::asdf()
{
if(singlelock->Lock()){
//this call to Lock always works
/// do some stuff

singlelock->Unlock();
}

myclass::junk()
{
if(singlelock->Lock()){
//if it fails, it is always from this function
/// do some other stuff

singlelock->Unlock();
}


any help is appreciated
ASKER CERTIFIED SOLUTION
Avatar of jstolan
jstolan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zube
zube

ASKER

What is a good way to check IsLocked()?

It's a time critical app so waiting a specified time before retrying will not be an ideal solution. A do {} while(IsLocked()) loop seems to be asking for problems.

Any hints?