Solved

CSingleLock Debug Assertion

Posted on 1998-10-06
2
552 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:zube
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 200 total points
ID: 1323033
I'm not sure what sort of multithreading you're doing.  However, it seems to me that you need to call the IsLocked() member function to make sure the object isn't already locked.  You need to do this before you call the Lock function.
0
 

Author Comment

by:zube
ID: 1323034
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?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 28
bigDiff challenge 17 83
Detect file exist or not 3 127
Updating statistics with error notification email in SQL server 4 71
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now