Click here to Skip to main content
15,927,694 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: video chat Pin
Jerry Evans27-Nov-03 3:54
Jerry Evans27-Nov-03 3:54 
GeneralErase external files Pin
chadell26-Nov-03 23:45
chadell26-Nov-03 23:45 
GeneralRe: Erase external files Pin
Cedric Moonen26-Nov-03 23:53
Cedric Moonen26-Nov-03 23:53 
GeneralRe: Erase external files Pin
chadell27-Nov-03 1:59
chadell27-Nov-03 1:59 
GeneralRe: Erase external files Pin
Neville Franks27-Nov-03 0:25
Neville Franks27-Nov-03 0:25 
GeneralRe: Erase external files Pin
Prakash Nadar27-Nov-03 1:01
Prakash Nadar27-Nov-03 1:01 
Generalstore and retrieve .bmp using sql server 2000 and vc++ 6.0 Pin
mctpursuer26-Nov-03 23:09
mctpursuer26-Nov-03 23:09 
GeneralA confusing problem... Pin
Rob Manderson26-Nov-03 23:03
protectorRob Manderson26-Nov-03 23:03 
I'm encountering a strange problem in multithreaded code (I can hear the groans now Smile | :) ). In a nutshell, my app is MDI where each document has a CListView attached. Each CListView spawns two threads. The first thread monitors a file and, when the file changes, reads the changes and adds the change records to a list. The second thread is signalled by the first thread when the list changes and updates the ListView with the new data.

As part of the shutdown sequence for the program I signal a stop event monitored by each thread which, when signalled, causes the thread to terminate. The stop event is manual reset. Then I wait upon each thread handle to be sure the thread has in fact terminated. Because the work in each thread is inside a loop not directly controlled by the WaitForXObject(s) call there's another boolean variable used to signal the thread, at each iteration of the loop, if I want it to return to the WaitForXObject(s) call. The thread that sets that variable sleeps for a couple of timeslices to be sure the threads see the change. (It makes no difference in the outcome if the thread that sets the variable sleeps 10 ms or 10 seconds).

It all works perfectly if I let it run to completion, ie
file changes
monitor thread notices changes and creates change records, adds them to list
update thread is signalled and copies new records into the view

but if I try to exit the app while the update thread is still processing change records the app hangs about half the time in a call to CListCtrl::InsertItem. I can let it sit there for an hour and nothing happens (and 0% CPU for the app). Breaking under the debugger when it's hung reveals the update thread is waiting for CListCtrl::InsertItem to return.

The thread procedure gets the this pointer to the CListView as the LPVOID parameter. Examining the code for CListCtrl::InsertItem reveals it's a simple wrapper around a ::SendMessage call using the HWND of the CListCtrl embedded in the view (ie, not using the MFC temporary CWnd mechanism. This explains why it works most of the time (no cross thread problems with CWnd's)).

When I break using the debugger during the hang I can see that the CListView is still valid and the embedded CListCtrl is also still valid (both have valid HWND's which Spy++ can see). So I can't imagine why it's hanging in the InsertItem call. Since the InsertItem call uses ::SendMessage rather than ::PostMessage it's not message pump related.

Any ideas? Any experience with hangs in CListCtrl::InsertItem?

Rob Manderson

http://www.mindprobes.net

"I killed him dead cuz he was stepping on my turf, cutting me out of my bling the same way my ho cuts cookies, officer"

"Alright then, move along"
- Ian Darling, The Lounge, Oct 10 2003
GeneralRe: A confusing problem... Pin
Ryan Roberts26-Nov-03 23:42
Ryan Roberts26-Nov-03 23:42 
GeneralRe: A confusing problem... Pin
Rob Manderson26-Nov-03 23:48
protectorRob Manderson26-Nov-03 23:48 
GeneralRe: A confusing problem... Pin
Mike Dimmick27-Nov-03 1:48
Mike Dimmick27-Nov-03 1:48 
GeneralRe: A confusing problem... Pin
Rob Manderson27-Nov-03 8:49
protectorRob Manderson27-Nov-03 8:49 
GeneralRe: A confusing problem... Pin
Mike Dimmick27-Nov-03 9:11
Mike Dimmick27-Nov-03 9:11 
GeneralRe: A confusing problem... Pin
Neville Franks27-Nov-03 0:23
Neville Franks27-Nov-03 0:23 
GeneralRe: A confusing problem... Pin
Rob Manderson27-Nov-03 8:50
protectorRob Manderson27-Nov-03 8:50 
GeneralRe: A confusing problem... Pin
Neville Franks27-Nov-03 9:10
Neville Franks27-Nov-03 9:10 
GeneralRe: A confusing problem... Pin
Roger Allen27-Nov-03 3:31
Roger Allen27-Nov-03 3:31 
GeneralDrop-Down toolbar Pin
shyampriya26-Nov-03 22:56
shyampriya26-Nov-03 22:56 
GeneralTemplate class in a vector Pin
Jerome Conus26-Nov-03 22:35
Jerome Conus26-Nov-03 22:35 
GeneralRe: Template class in a vector Pin
Mike Dimmick27-Nov-03 2:01
Mike Dimmick27-Nov-03 2:01 
GeneralOutlook Express please help Pin
Jump_Around26-Nov-03 21:57
Jump_Around26-Nov-03 21:57 
GeneralSpawning error Pin
Cedric Moonen26-Nov-03 21:51
Cedric Moonen26-Nov-03 21:51 
GeneralRe: Spawning error Pin
Prakash Nadar26-Nov-03 23:47
Prakash Nadar26-Nov-03 23:47 
GeneralRe: Spawning error Pin
Cedric Moonen26-Nov-03 23:57
Cedric Moonen26-Nov-03 23:57 
GeneralVisual C++ 6 and Oracle rman Pin
steffen241226-Nov-03 21:16
steffen241226-Nov-03 21:16 

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.