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

Thread join in MFC

796 views
Skip to first unread message

Coder

unread,
May 24, 2005, 6:52:14 AM5/24/05
to
hi, in my multithreaded application i need to wait for a thread to finish
its work.

example:
// i create thread like that
::AfxBeginThread(..) // returns a CWinThread *

// My question is, in this case how can i use a mechanism like thread.join()
??

thanks in advance..


Coder

unread,
May 24, 2005, 7:12:27 AM5/24/05
to
CWinThread *my_thread;

my_thread = AfxBeginThread(...);

..
.

::WaitForSingleObject(my_thread, INFINITE);

// WaitForSingleObject seems OK, any comments??


Scott McPhillips [MVP]

unread,
May 24, 2005, 8:41:48 AM5/24/05
to

WaitForSingleObject(my_thread->m_hThread, INFINITE);

--
Scott McPhillips [VC++ MVP]

Coder

unread,
May 24, 2005, 8:41:14 AM5/24/05
to
i will change it, 10x ..


Chris Burnette

unread,
May 24, 2005, 12:50:26 PM5/24/05
to
You also need to set the m_bAutoDelete field to false. Otherwise, the
CWinThread* could be deleted.

CWinThread* pthr = AfxBeginThread(..., CREATE_SUSPENDED, ...);
pthr->m_bAutoDelete = FALSE;

...

::WaitForSingleObject(pthr->m_hThread, INFINITE);
delete pthr;

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:%23VZkWWF...@TK2MSFTNGP15.phx.gbl...

Doug Harrison [MVP]

unread,
May 24, 2005, 2:21:01 PM5/24/05
to

Use WaitForSingleObject and related functions. See this message for much
more on this and other MFC multithreading issues:

http://groups-beta.google.com/group/microsoft.public.vc.mfc/msg/10f8a2138b08f866?hl=en

--
Doug Harrison
Microsoft MVP - Visual C++

0 new messages