How to change the name of the stream

I have a server application that uses a lot of threads. Not wanting to enter into the argument about how many threads it really should use, it would be nice to see some descriptive text in the "streams" window of the debugger, describing that each of them, without having to go to it and determine from the context what it is.

They all have the same starting address, so, as a rule, the thread window says something like "thread_base :: start" or something like that. I would like to know if there is an API call or something that allows me to customize this text.

+9
c ++ multithreading winapi
Jan 26 '09 at 4:55
source share
3 answers
+8
Jan 26 '09 at 5:04
source share

Here is the code I'm using.

This is the header file.

#pragma once #define MS_VC_EXCEPTION 0x406d1388 #pragma warning(disable: 6312) #pragma warning(disable: 6322) typedef struct tagTHREADNAME_INFO { DWORD dwType; // must be 0x1000 LPCSTR szName; // pointer to name (in same addr space) DWORD dwThreadID; // thread ID (-1 caller thread) DWORD dwFlags; // reserved for future use, most be zero } THREADNAME_INFO; inline void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) { #ifdef _DEBUG THREADNAME_INFO info; info.dwType = 0x1000; info.szName = szThreadName; info.dwThreadID = dwThreadID; info.dwFlags = 0; __try { RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (DWORD *)&info); } __except (EXCEPTION_CONTINUE_EXECUTION) { } #else dwThreadID; szThreadName; #endif } 

Then I call it like this in the proc stream.

 SetThreadName(GetCurrentThreadId(), "VideoSource Thread"); 

It's worth noting that this is the exact code that David posted the link to (thanks! I forgot where I got it). I did not delete this message because I would like the code to still be available if MSDN decides to reorganize its links (again).

+11
Jan 26 '09 at 5:18
source share

Windows 10 added SetThreadDescription (), on this platform this will be the best method.

0
Jun 18 '17 at 23:03
source share



All Articles