473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

ASSERTs are killing my multithreaded MFC app!

3
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:
http://www.thescripts.com/forum/thread283101.html

[code]
class CQCriticalSection
{
public:
CQCriticalSection(CSingleLock* pcslLock);
virtual ~CQCriticalSection();
private:
CSingleLock* m_pcslLock;
};

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

CQCriticalSection::~CQCriticalSection()
{if (m_pcslLock != static_cast<CSingleLock*>(0))
{
m_pcslLock->Unlock();
}
}
Apr 17 '07 #1
1 1480
werp
3
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

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

Similar topics

9
by: John Lull | last post by:
I'm writing a multithreaded COM server to manage a pool of hardware resources. All objects are designed to be thread-safe, and I've set sys.coinit_flags to COINIT_MULTITHREADED before importing...
6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
6
by: Dan Kelley | last post by:
We have a multithreaded app that responds to events, and writes these events to a text file. This text file is used by an external system for further processing. We want to be able to write...
1
by: daniel.bron | last post by:
I'm maintaining a C++ application written by a developer who has now left. The app is a multithreaded client/server app for financial data. My compiler is MS visual C++ 6.0. I'm a C++ neophyte....
3
by: Development | last post by:
I am creating 10 threads that do ecatly the same thing. I am having a very hard time debugging this scenario. It seems that by default when you are doing f10 or f11 all threads execute. You can...
7
by: Pavils Jurjans | last post by:
Hello, I wanted to get some light in the subject. As I develop ASP.NET applications, it's necessary to understand how exactly the server- communication happens. It seems like initially...
9
by: Jay | last post by:
How do I stop execution of remaining sub procesures in a multithreaded app? For example: sub form_load dim i as integer for i = 1 to 5 '5 threads dim ts as threadstart(addressof...
3
by: | last post by:
Is it possible to have just a multithreaded sub procedure? What I need is a timer time_elapsed event (2 sec interval) send params to a sub that is multithreaded. I have a COM component used to...
6
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small functions that you'd like 100s or 1000s of it seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.