Article View: borland.public.cppbuilder.nativeapi
Article #14729Re: How to name the thread
From: Remy Lebeau (TeamB)
Date: Mon, 04 Aug 2003 08:39
Date: Mon, 04 Aug 2003 08:39
56 lines
2976 bytes
2976 bytes
"Boguslaw Fries" <B.Fries@luca-online.de> wrote in message
news:3f2e02bf@newsgroups.borland.com...
> I have the list of all active thread of my program... there
> are process number i handles Is any possibility , when I
> start my thread using _beginthread to name it, and after
> connect the name to the process number and handle?
Not in the way in which your question suggests that you want to use it.
Which version of BCB are you using? Only BCB6 natively supports naming
threads, and even then it only supports it for TThread-based threads.
Otherwise, you have to set the name manually by throwing a special
0x406D1388 exception via RaiseException() containing a THREADNAME_INFO
structure instance, ie:
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;
static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName )
{
THREADNAME_INFO info = {0};
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) {}
}
Then your thread code can call SetThreadName() as its first statement:
DWORD WINAPI MyThreadFunc( LPVOID )
{
SetThreadName( -1, "My Thread Name" );
// your normal thread code here
}
Note that this will only work if your program is being run inside a debugger
that recognizes exception 0x406D1388, it does not work outside of the
debugger at all. And there is no way to programmably query a thread name
after it has been set, it is only used for the debugger's benefit when
keeping track of active threads and displaying them to you during debugging.
Gambit
Technical Details
Message-ID:
<3f2e1a5a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f2e02bf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ab979edf7e7676fa X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-04 01:36:18 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f2e02bf@newsgroups.borland.com> Subject: Re: How to name the thread Date: Mon, 4 Aug 2003 01:39:41 -0700 Lines: 58 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3f2e1a5a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059986010 207.175.226.26 (4 Aug 2003 01:33:30 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail