AfxBeginThread and Thread ID

Posted on 2006-04-05
Last Modified: 2013-11-20
Ah hello.

I am creating a thread via AfxBeginThread, and I would like to know how I can get hold of the ID of the thread.  I can obviously assign some data structure to the thread that contains some identifier, but I would like to know the correct way to get the ID.

Any ideas ?

Question by:mrwad99
    LVL 48

    Accepted Solution

    AfxBeginThread returns CWinThread*. CWinThread::m_nThreadID is thread ID.
    LVL 19

    Author Comment

    Thanks.  And I can rely on the fact that each thread will have a *completely unique* ID, yes ?
    LVL 48

    Expert Comment

    Every thread has unique ID among currrently running threads. Otherwise OpenThread API could open wrong thread.
    I don't know whether created thread ID can be equal to ID of thread which finished some time before.
    LVL 43

    Expert Comment

    <I don't know whether created thread ID can be equal to ID of thread which finished some time before.>

    I suspect it *could* be - Why should windows need to keep track of non-existant threads?
    LVL 19

    Author Comment

    Thanks AlexFM.  Andy: interesting, worth keeping in mind.

    If anyone is interested, I have a stinker of a problem at http:Q_21802368.html on a similar slant to this one

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now