Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CSingleLock Debug Assertion

Posted on 1998-10-06
2
Medium Priority
?
570 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 400 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 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