While i was working with threads in VC++ i saw that in the thread list each thread has name field.
And every Thread was named Win32 Thread. Some how that annoyed me alot and i found a solution to give threads names.
Here the code to name a thread. This code was taken from MSDN and i suggest only to use it in debug builds.
Display All
Now with SetThreadName you can name your thread. But to do so you need the thread Id to make this.
On Windows Xp there is no way to get the thread id with out running the thread and call GetCurrentThreadID
So here the solution to solve this.
Display All
You will pass this Struct to the thread entry point which looks like this.
Display All
And every Thread was named Win32 Thread. Some how that annoyed me alot and i found a solution to give threads names.
Here the code to name a thread. This code was taken from MSDN and i suggest only to use it in debug builds.
Source Code
- typedef struct tagTHREADNAME_INFO
- {
- DWORD dwType; // must be 0x1000
- LPCSTR szName; // pointer to name (in user addr space)
- DWORD dwThreadID; // thread ID (-1=caller thread)
- DWORD dwFlags; // reserved for future use, must be zero
- } THREADNAME_INFO;
- void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
- {
- THREADNAME_INFO info;
- info.dwType = 0x1000;
- info.szName = szThreadName;
- info.dwThreadID = dwThreadID;
- info.dwFlags = 0;
- __try
- {
- RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );
- }__except (EXCEPTION_CONTINUE_EXECUTION)
- {
- }
- }
Now with SetThreadName you can name your thread. But to do so you need the thread Id to make this.
On Windows Xp there is no way to get the thread id with out running the thread and call GetCurrentThreadID
So here the solution to solve this.
Source Code
You will pass this Struct to the thread entry point which looks like this.