Appendices > Portable Thread Library > Threads > Thread Identifier and Thread Names
 
Thread Identifier and Thread Names
Each thread has a unique identifier which can be used to locate the thread in trace messages. If possible, the chosen identifier should be the same as the one that appears in the debugger on the machine you are using.
Operators are provided to write the thread identifier out to a stream for trace messages. You can give names to threads (instead of identifiers) by subclassing the thread and providing the virtual member function IlsThread::getName.
An example of this is shown below:
class namedThread : public IlsThread
{
public:
namedThread(IlsThreadObjectName nm,
IlsThreadStartFunc f,
IlsAny a = 0)
: IlsThread(f, a, s), _name(0)
{
_name = new char[strlen(nm)+1];
strcpy(_name, nm);
}
virtual ~namedThread(){delete [] _name;}
virtual IlsThreadObjectName getName() const {return _name;}
private:
IlsThreadObjectName _name;
};
Note: Subclassing a thread object applies to all classes in the portable library.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.