When you create a TThread child using the tool palette in your BDS, you can specify a name for the thread. Here is the automatically generated code. You simply call the SetName () function in the Execute method, and the thread calling this method is given a name in some strange way ...
{$IFDEF MSWINDOWS} type TThreadNameInfo = record FType: LongWord; // must be 0x1000 FName: PChar; // pointer to name (in user address space) FThreadID: LongWord; // thread ID (-1 indicates caller thread) FFlags: LongWord; // reserved for future use, must be zero end; {$ENDIF} { TTestThread } procedure TTestThread.SetName; {$IFDEF MSWINDOWS} var ThreadNameInfo: TThreadNameInfo; {$ENDIF} begin {$IFDEF MSWINDOWS} ThreadNameInfo.FType := $1000; ThreadNameInfo.FName := 'ThreadName'; ThreadNameInfo.FThreadID := $FFFFFFFF; ThreadNameInfo.FFlags := 0; try RaiseException( $406D1388, 0, sizeof(ThreadNameInfo) div sizeof(LongWord), @ThreadNameInfo ); except end; {$ENDIF} end;
I believe this is really useful when debugging, since you can see not only the TID, but also the thread names assigned in this way. You know which stream is due to this.
Please tell me, however, if the assigned name can be obtained in any way. Can it be read based on the stream descriptor? Or can it be read even from an βexternalβ process by another process? You know, there are applications that list the processes and threads running in them. Will this name be available for such applications?
Thanks!
Mariusz schimke
source share