Solved

CSingleLock Debug Assertion

Posted on 1998-10-06
2
563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 101
Hibernate methods 2 88
MaxSpan challenge 9 139
Notepad++ Question 11 26
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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