![]() |
General Programming »
Threads, Processes & IPC »
Threads
Advanced
Name your threads in the VC debugger thread listBy Patrick HoffmannThe VC debugger displays a name for every thread. This article describes how to control what VC displays in the thread list. |
VC6, VC7, VC7.1, VC8.0Win2K, WinXP, Win2003, Vista, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

Some days ago, someone asked me if it is possible to rename threads in the VC debugger. Because I worked at a multi threading project myself those days, I was very interested in realizing this idea. Some Google group searches later, I had a solution that is short and easy. Because this could be very helpful for everyone working on applications with many threads, I publish it here.
There isn't much to understand except, that the VC debugger gets the information about a thread's name via the exception #0x406D1388.
I put the necessary call into a simple function. Here is the code:
// // Usage: SetThreadName (-1, "MainThread"); // 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) { } }
You just have to call SetThreadName() with the thread ID and a name string as parameters.
Have fun with that tiny tool ;)
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 13 Oct 2004 Editor: Smitha Vijayan |
Copyright 2004 by Patrick Hoffmann Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |