getting the handle for a thread

Discussion in 'C++' started by PaulH, Sep 25, 2006.

  1. PaulH

    PaulH Guest

    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(???);
    }
    PaulH, Sep 25, 2006
    #1
    1. Advertising

  2. PaulH

    Noah Roberts Guest

    PaulH wrote:
    > 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.
    Noah Roberts, Sep 25, 2006
    #2
    1. Advertising

  3. PaulH wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Sep 25, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    637
    Joe Smith
    Jul 22, 2004
  2. lucy
    Replies:
    2
    Views:
    641
  3. Leon
    Replies:
    2
    Views:
    521
  4. Replies:
    0
    Views:
    558
  5. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    445
    hanumizzle
    Oct 6, 2006
Loading...

Share This Page