getting the handle for a thread

P

PaulH

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(???);
}
 
N

Noah Roberts

PaulH said:
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?

All of the above is platform specific. You need to ask these questions
in a newsgroup that's subject includes the platform or library you are
using for threading.
 
V

Victor Bazarov

PaulH said:
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?

It seems that you're in a wrong newsgroup. None of the functions you
mention exist in standard C++ language, the topic of this newsgroup.
Perhaps you need to visit 'comp.os.ms-windows.programmer.win32' or some
such...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top