469,568 Members | 1,498 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

ASSERTs are killing my multithreaded MFC app!

I am using CCriticalSection and CSingleLock in an MFC app. I have created an object and pass into it a CCriticalSection from the main app. Then I make a thread. The thread constantly writes data to some structures. The main app then reads those same structures hoping that the CCriticalSection and CSingleLock will block the read until the write thread has lost access to the structures.

What happens is ASSERT! I keep finding that my CSingleLock.m_bAcquired == true. When this happens the ASSERT pounds the desktop.

I don't understand how m_bAcquired becomes true.

I create the locking mechanism with a wrapper class. It is included below.
Please note that my destructor is doing an Unlock.
Please note that my constructor accepts a CSingleLock instantiated with the CCriticalSection created in the main thread.
The CSingleLock is static in the class that consumes the code below.

FYI: I have read the following thread and it doesn't appear to be relevant:

class CQCriticalSection
CQCriticalSection(CSingleLock* pcslLock);
virtual ~CQCriticalSection();
CSingleLock* m_pcslLock;

CQCriticalSection::CQCriticalSection(CSingleLock* pcslLock)
_ASSERT(pcslLock != static_cast<const CSingleLock*>(0));
m_pcslLock = pcslLock;

{if (m_pcslLock != static_cast<CSingleLock*>(0))
Apr 17 '07 #1
1 1335
My fault here was accepting a CSingleLock as a parameter into my constructor. I should have made a CSingleLock local by creating it the constructor and instead have passed into the constructor a CCriticalSection.

Doing this solved my issues.
Apr 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by John Lull | last post: by
6 posts views Thread by Dan Kelley | last post: by
1 post views Thread by daniel.bron | last post: by
3 posts views Thread by Development | last post: by
7 posts views Thread by Pavils Jurjans | last post: by
6 posts views Thread by Roger Heathcote | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.