Click here to Skip to main content
15,445,997 members
Home / Discussions / C / C++ / MFC

C / C++ / MFC

GeneralRe: Need help to use the Sort Iist Control with XP-Style! Pin
Anonymous1-Jun-05 1:22
MemberAnonymous1-Jun-05 1:22 
GeneralRe: Need help to use the Sort Iist Control with XP-Style! Pin
bosfan1-Jun-05 2:23
Memberbosfan1-Jun-05 2:23 
GeneralCListBox with titles Pin
Vaclav30-May-05 23:20
MemberVaclav30-May-05 23:20 
GeneralRe: CListBox with titles Pin
S Douglas31-May-05 1:04
professionalS Douglas31-May-05 1:04 
GeneralRe: CListBox with titles Pin
David Crow31-May-05 3:38
MemberDavid Crow31-May-05 3:38 
QuestionShell functions and versions ? Pin
Ramsus30-May-05 23:07
MemberRamsus30-May-05 23:07 
AnswerRe: Shell functions and versions ? Pin
David Crow31-May-05 3:41
MemberDavid Crow31-May-05 3:41 
GeneralMultithreaded horror.. Pin
Bob Stanneveld30-May-05 22:04
MemberBob Stanneveld30-May-05 22:04 

I have a very strange error in my multithreaded application. The situation is as follows:

[thread 1]
I have one dialog window open, this dialog spawns 2 threads (thread 2, thread 3] when it is initialized.

[thread 2]
This thread spawns two other threads (thread 4, thread 5). After spawning those threads, it retrieves data from a buffer
The two other threads are identical and retrieve data from 2 diffenrent COMM ports and put the data in the buffer.
When data is successfully retrieved, it notifies thead 3.
Before shutting down, it notifies the monitor thread (3) and shuts down thread 4 and 5. It waits until the threads are cleaned up.

[thread 3]
Its sole purpose is to monitor thread 2 and notify the dialog when data is arrived.
This thread cleans up itself after it recieved the notification that thread 2 is stopped.

[thread 3, thread 4]
These two threads retrieve data from two different COMM ports. The retrieved data is stored in a std::vector managed by thread 2.

You may think that I have too much thread for this purpose (2 would be enough for this type of work), but this is by design. The extra monitor thread is used because this is a test application. In the real application the monitor threads do some real work.

Now for the problem. Everything works like a charm, except when I try to stop thread 2. It actually manages to stop thread 3 and 4. After that, the thread is cleaned up (the thread 2 and 3 are gone in PView thread 2 not). But then, BANG the program crashes in the middle of the following function: AfxUnlockTempMaps at the following line: pThreadState->m_pSafetyPoolBuffer = malloc(pApp->m_nSafetyPoolSize);
The error message in the output window of VS2005 is:
Unhandled exception at 0x02845922 (dbghelp.dll) in TestInput.exe: 0xC0000005: Access violation reading location 0x0152070c.

The location is always the same and no pointer is even near that address...

I noticed that the problem does not occur when thread 3 and 4 stop sending data to the buffer of thread 2. Here are some code snippets:
The call where the data is added to the buffer of thread 2

The AddDataToInternalBuffer function
void AddDataToInternalBuffer(SERIAL_DATA& SerialData)

Does anybody have a clue what might be happening?

GeneralProblem solved.. Pin
Bob Stanneveld31-May-05 2:38
MemberBob Stanneveld31-May-05 2:38 
GeneralVisual C++ Pin
Member 150607130-May-05 21:40
MemberMember 150607130-May-05 21:40 
GeneralRe: Visual C++ Pin
Cedric Moonen30-May-05 21:50
MemberCedric Moonen30-May-05 21:50 
GeneralRe: Visual C++ Pin
toxcct30-May-05 22:26
Membertoxcct30-May-05 22:26 
GeneralRe: Visual C++ Pin
benjymous30-May-05 23:21
Memberbenjymous30-May-05 23:21 
GeneralRe: Visual C++ Pin
David Crow31-May-05 3:48
MemberDavid Crow31-May-05 3:48 
QuestionHow To Create a Transparent Pen? Pin
pritamkd30-May-05 20:45
Memberpritamkd30-May-05 20:45 
Questionhow to display string in debug widow. Pin
shumyla198330-May-05 20:31
Membershumyla198330-May-05 20:31 
AnswerRe: how to display string in debug widow. Pin
MK7830-May-05 20:35
MemberMK7830-May-05 20:35 
AnswerRe: how to display string in debug widow. Pin
BlackDice31-May-05 5:38
MemberBlackDice31-May-05 5:38 
Generalquestion regarding operator overloading! Pin
namaskaaram30-May-05 19:15
Membernamaskaaram30-May-05 19:15 
GeneralRe: question regarding operator overloading! Pin
Johnny ²30-May-05 19:35
MemberJohnny ²30-May-05 19:35 
GeneralRe: question regarding operator overloading! Pin
Rahim Rattani30-May-05 19:45
MemberRahim Rattani30-May-05 19:45 
GeneralRe: question regarding operator overloading! Pin
S. Senthil Kumar30-May-05 20:58
MemberS. Senthil Kumar30-May-05 20:58 
GeneralRe: question regarding operator overloading! Pin
namaskaaram30-May-05 21:53
Membernamaskaaram30-May-05 21:53 
GeneralCListCtrl auto scrolling problem Pin
Imtiaz Murtaza30-May-05 18:53
MemberImtiaz Murtaza30-May-05 18:53 
GeneralRe: CListCtrl auto scrolling problem Pin
namaskaaram30-May-05 22:34
Membernamaskaaram30-May-05 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.