Click here to Skip to main content
15,171,993 members
Articles / Programming Languages / C++
Posted 13 Oct 2004


47 bookmarked

Name your threads in the VC debugger thread list

Rate me:
Please Sign up or sign in to vote.
4.27/5 (20 votes)
13 Oct 2004
The VC debugger displays a name for every thread. This article describes how to control what VC displays in the thread list.

Sample Image - Name_threads_in_debugger.png


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

void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
    info.dwType = 0x1000;
    info.szName = szThreadName;
    info.dwThreadID = dwThreadID;
    info.dwFlags = 0;
    RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );

You just have to call SetThreadName() with the thread ID and a name string as parameters.

Have fun with that tiny tool ;)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Patrick Hoffmann
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

GeneralMy vote of 2 Pin
Sarath C5-Mar-09 8:56
MemberSarath C5-Mar-09 8:56 
GeneralI'm having a "Fifth Element" moment here... Pin
AndreyT4-Apr-08 12:56
MemberAndreyT4-Apr-08 12:56 
GeneralNice article Pin
ThatsAlok25-Jul-07 20:57
MemberThatsAlok25-Jul-07 20:57 
Questionhow i can have optional number of threads?? Pin
kamelian_2014-Mar-07 23:08
Memberkamelian_2014-Mar-07 23:08 
GeneralHere is a hint Pin
ndl19-Apr-06 8:04
Memberndl19-Apr-06 8:04 
QuestionAttaching to Process Pin
robma3-Nov-05 12:22
Memberrobma3-Nov-05 12:22 
AnswerRe: Attaching to Process Pin
Patrick Hoffmann3-Nov-05 13:38
MemberPatrick Hoffmann3-Nov-05 13:38 
GeneralThanks Patrick Pin
Just someone else13-Oct-04 3:04
MemberJust someone else13-Oct-04 3:04 
GeneralRe: Thanks Patrick Pin
Neville Franks13-Oct-04 10:55
MemberNeville Franks13-Oct-04 10:55 
QuestionWhy repeating the MSDN !? Pin
Jochen Kalmbach [MVP VC++]13-Oct-04 1:42
MemberJochen Kalmbach [MVP VC++]13-Oct-04 1:42 
AnswerRe: Why repeating the MSDN !? Pin
Patrick Hoffmann13-Oct-04 2:23
MemberPatrick Hoffmann13-Oct-04 2:23 
AnswerDoes this only work in .NET? Pin
aaron.pedigo13-Oct-04 3:31
Memberaaron.pedigo13-Oct-04 3:31 
GeneralRe: Does this only work in .NET? Pin
Jochen Kalmbach [MVP VC++]13-Oct-04 4:03
MemberJochen Kalmbach [MVP VC++]13-Oct-04 4:03 
GeneralRe: Does this only work in .NET? Pin
Jochen Kalmbach [MVP VC++]13-Oct-04 4:08
MemberJochen Kalmbach [MVP VC++]13-Oct-04 4:08 
GeneralRe: Does this only work in .NET? Pin
aaronp13-Oct-04 6:28
Memberaaronp13-Oct-04 6:28 
GeneralRe: Does this only work in .NET? Pin
Jochen Kalmbach [MVP VC++]13-Oct-04 10:26
MemberJochen Kalmbach [MVP VC++]13-Oct-04 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.