Click here to Skip to main content
15,894,955 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionA Shading algorithm ? Pin
yarp21-Aug-02 6:01
yarp21-Aug-02 6:01 
AnswerRe: A Shading algorithm ? Pin
Chris Losinger21-Aug-02 7:13
professionalChris Losinger21-Aug-02 7:13 
GeneralRe: A Shading algorithm ? Pin
Stephane Rodriguez.21-Aug-02 7:27
Stephane Rodriguez.21-Aug-02 7:27 
GeneralRe: A Shading algorithm ? Pin
yarp21-Aug-02 21:54
yarp21-Aug-02 21:54 
GeneralChris Maudre Datagrid Pin
Mazdak21-Aug-02 5:35
Mazdak21-Aug-02 5:35 
GeneralRe: Chris Maudre Datagrid Pin
Chris Losinger21-Aug-02 5:36
professionalChris Losinger21-Aug-02 5:36 
GeneralRe: Chris Maudre Datagrid Pin
Mazdak21-Aug-02 7:29
Mazdak21-Aug-02 7:29 
Generalterminate a worker thread Pin
lucy21-Aug-02 5:31
lucy21-Aug-02 5:31 
I have a Dialog based MFC program, and in CMyDialogDlg::OnCreate I start my worker thread like this:
m_bThreadRun = TRUE;
HANDLE hThread = AfxBeginThread(MyWorkerThread, this);
if ( hThread == NULL )
    MessageBox("Cannot start worker thread.");


While in my worker thread, I check for the flag from parent:
UINT MyWorkerThread(LPVOID pParam)
{
    CMyDialogDlg * pDlg = (CMyDialogDlg *)pParam;
    while ( pDlg->m_bThreadRun)
    {
        // do something
    }
    TRACE("exit from the worker thread");
    return 0;
}


In order to terminate this worker thread, I did this:
CMyDialogDlg::OnClose()
{
   m_bThreadRun = FALSE;
   CDialog::OnClose();
}

But what troubles me is:
1. The trace line of my worker thread function "exit from the worker thread" was never printed.
2. When the program ended, this will appear in my Visual studio debug window:
etected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {54} client block at 0x017B4558, subtype 0, 112 bytes long.
a CWinThread object at $017B4558, 112 bytes long
Object dump complete.


what I am missing here? How can I terminate this worker thread gracefully?

Thanks a lot for your help!
GeneralRe: terminate a worker thread Pin
Tomasz Sowinski21-Aug-02 5:38
Tomasz Sowinski21-Aug-02 5:38 
GeneralRe: terminate a worker thread Pin
lucy21-Aug-02 6:01
lucy21-Aug-02 6:01 
GeneralRe: terminate a worker thread Pin
RChin21-Aug-02 23:43
RChin21-Aug-02 23:43 
GeneralRe: terminate a worker thread Pin
lucy22-Aug-02 2:41
lucy22-Aug-02 2:41 
GeneralRe: terminate a worker thread Pin
Chris Losinger21-Aug-02 5:41
professionalChris Losinger21-Aug-02 5:41 
GeneralRe: terminate a worker thread Pin
lucy21-Aug-02 6:08
lucy21-Aug-02 6:08 
GeneralRe: terminate a worker thread Pin
Chris Losinger21-Aug-02 6:16
professionalChris Losinger21-Aug-02 6:16 
GeneralRe: terminate a worker thread Pin
lucy21-Aug-02 7:17
lucy21-Aug-02 7:17 
Generalquick question about recordsets, ADO Pin
ns21-Aug-02 4:54
ns21-Aug-02 4:54 
GeneralRe: quick question about recordsets, ADO Pin
Ravi Bhavnani21-Aug-02 5:24
professionalRavi Bhavnani21-Aug-02 5:24 
GeneralRe: quick question about recordsets, ADO Pin
Ravi Bhavnani21-Aug-02 5:25
professionalRavi Bhavnani21-Aug-02 5:25 
GeneralRe: quick question about recordsets, ADO Pin
Blade[DMS]21-Aug-02 5:28
Blade[DMS]21-Aug-02 5:28 
GeneralI tried this, but Pin
ns21-Aug-02 5:36
ns21-Aug-02 5:36 
GeneralRe: I tried this, but Pin
Ravi Bhavnani21-Aug-02 5:39
professionalRavi Bhavnani21-Aug-02 5:39 
GeneralRe: I tried this, but Pin
ns21-Aug-02 5:46
ns21-Aug-02 5:46 
GeneralRe: I tried this, but Pin
Ravi Bhavnani21-Aug-02 5:51
professionalRavi Bhavnani21-Aug-02 5:51 
GeneralRe: I tried this, but Pin
Blade[DMS]21-Aug-02 5:49
Blade[DMS]21-Aug-02 5:49 

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.