AfxBeginThread and Thread ID

Posted on 2006-04-05
Medium Priority
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
  • 2
  • 2
LVL 48

Accepted Solution

AlexFM earned 500 total points
ID: 16379634
AfxBeginThread returns CWinThread*. CWinThread::m_nThreadID is thread ID.
LVL 19

Author Comment

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

Expert Comment

ID: 16379770
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 45

Expert Comment

ID: 16380265
<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

ID: 16380762
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 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