Solved

CSingleLock Debug Assertion

Posted on 1998-10-06
2
550 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 82
while loop over for loop 7 79
no14 challenge 14 56
Unix Command -- Challenging  question 7 79
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

10 Experts available now in Live!

Get 1:1 Help Now