Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem exiting application due to infinite loop in a thread

166 views
Skip to first unread message

azsx

unread,
Feb 16, 2007, 7:56:23 PM2/16/07
to
Hi. I make a program with Visual C++. First I create, show and update
a Window. Then I launch a thread which has and endless loop. After
that I get, translate and dispatch the messages for my window. When I
close the window, the system distroys it, but the program doesn't
exit. It does only if i remove my loop from the thread. Here is some
code:
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE
hPrevInstance,LPSTR lpszCmdLine, int nCmdShow){
......../// variables defined
HWND hwndMain = CreateWindow("MainWndClass",
"Sample",WS_OVERLAPPEDWINDOW,100,100,250,210,NULL,NULL, hinst,NULL);
if(!hwndMain)
return FALSE;
ShowWindow(hwndMain,nCmdShow);
UpdateWindow(hwndMain);
_beginthread(myThread, 0,NULL);
while((bRet=GetMessage(&msg,NULL,0,0))!=0){
if (bRet == -1){}
else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
void myThread(void *param){
// while(1)
// ;//nothing
//if loop commented everything is OK and program exits, otherwise
windows is closing but program wouldn't exit.
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wparam,LPARAM
lparam){
if (Message == WM_DESTROY ){
W.stop();
PostQuitMessage(0);
return 0;
}
}
Can you help?

David Craig

unread,
Feb 17, 2007, 1:16:36 AM2/17/07
to
Why would destroying the message thread cause the other thread to die? Take
a course in multi-threaded, multi-processing, and multi-tasking operating
systems design, theory, and practice. Also read the Remarks section for
_beginthread.

"azsx" <radu_p...@yahoo.com> wrote in message
news:1171673783.5...@k78g2000cwa.googlegroups.com...

azsx

unread,
Feb 17, 2007, 4:33:41 AM2/17/07
to

> Why would destroying the message thread cause the other thread to die? Take
> a course in multi-threaded, multi-processing, and multi-tasking operating
> systems design, theory, and practice. Also read the Remarks section for
> _beginthread.

Any books I should consider?

Arkady Frenkel

unread,
Feb 18, 2007, 2:30:41 AM2/18/07
to
IMHO the best is
http://www.amazon.com/Programming-Applications-Microsoft-Windows-General/dp/1572319968/sr=1-6/qid=1171783637/ref=sr_1_6/102-9421055-4628951?ie=UTF8&s=books
but in your case ( just to start ) define bool IsContinue ( init to true )
set it to false in your WndProc WM_DESTROY case and check that in your
thread to return
Arkady

"azsx" <radu_p...@yahoo.com> wrote in message

news:1171704821....@m58g2000cwm.googlegroups.com...

azsx

unread,
Feb 18, 2007, 5:11:05 AM2/18/07
to
thanks!

0 new messages