SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
A wrapper for platform-specific thread IDs. More...
#include <rw/sync/RWThreadId.h>
Public Member Functions | |
RWThreadId () | |
RWThreadId (RWStaticCtor) | |
RWThreadId (const RWThreadIdRep &threadIdRep) | |
~RWThreadId () | |
void | clear () |
unsigned | hash () const |
bool | isValid () const |
RWThreadId & | operator= (const RWThreadId &second) |
operator RWThreadIdRep & () const | |
RWThreadIdRep * | getRep () const |
bool | operator== (const RWThreadId &second) const |
bool | operator!= (const RWThreadId &second) const |
Static Public Member Functions | |
static bool | isSelf (const RWThreadId &id) |
static RWThreadId | self () |
Related Functions | |
(Note that these are not member functions.) | |
typedef unsigned | RWThreadIdRep |
typedef pthread_t | RWThreadIdRep |
typedef thread_t | RWThreadIdRep |
typedef unsigned | RWThreadIdRep |
unsigned | rwThreadHash (const RWThreadId &id) |
RWThreadId | rwThreadId () |
RWThreadId is a wrapper for platform-specific thread IDs. An RWThreadId represents the identification given by the underlying thread API to a specific thread of execution. The native thread IDs are used to identify and control these threads in the native thread API, but are not necessarily related to any Threads Module objects. You can get an instance of RWThreadId directly from a runnable object using the RWRunnableHandle::threadId() member function, or you can call the global function rwThreadId() to get an RWThreadId associated with the current thread. A thread ID is valid only while the separate thread of execution exists.
The global rwThread() function may be used to determine the threaded runnable object, if any, associated with the current thread of execution. Use the rwThreadHash() function to retrieve a unique integer value associated with a thread id for output or debugging purposes. Do not attempt to stream an RWThreadId instance directly, as the native thread ID type that this class represents may be a structure and not a simple scalar.
#include <rw/thread/rwtMakeThreadFunction.h> #include <rw/sync/RWThreadId.h> void whoamiReally() { RWThreadId myID = rwThreadId(); cout << "My native thread ID is" << RWThreadHash(myID) << endl; } int main() { RWThread t1, t2, t3; (t1 = rwtMakeThreadFunction(whoamiReally)).start(); (t2 = rwtMakeThreadFunction(whoamiReally)).start(); (t3 = rwtMakeThreadFunction(whoamiReally)).start(); t1.join(); t2.join(); t3.join(); return 0; } Program output: My native thread ID is 4 My native thread ID is 5 My native thread ID is 6
RWThreadId::RWThreadId | ( | ) | [inline] |
Creates an RWThreadId object not associated with any thread.
RWThreadId::RWThreadId | ( | RWStaticCtor | ) | [inline] |
Constructs a static instance, but does no direct initialization. Static instances are zero initialized, resulting in an RWThreadId with an invalid state.
RWThreadId::RWThreadId | ( | const RWThreadIdRep & | threadIdRep | ) | [inline] |
Creates an RWThreadId object directly from a native thread ID.
RWThreadId::~RWThreadId | ( | ) | [inline] |
Destructor.
void RWThreadId::clear | ( | void | ) | [inline] |
Clears the native thread ID so it won't match other native IDs.
RWThreadIdRep * RWThreadId::getRep | ( | ) | const [inline] |
Returns the address of the native thread ID member.
unsigned RWThreadId::hash | ( | ) | const [inline] |
Returns a hash of the thread ID.
bool RWThreadId::isSelf | ( | const RWThreadId & | id | ) | [inline, static] |
Returns true
if id matches the thread ID of the currently running thread; otherwise, returns false
.
bool RWThreadId::isValid | ( | void | ) | const [inline] |
Returns true
if this thread ID was constructed or assigned from a native thread instance, otherwise false
.
RWThreadId::operator RWThreadIdRep & | ( | ) | const [inline] |
Returns a reference to the native thread ID.
bool RWThreadId::operator!= | ( | const RWThreadId & | second | ) | const [inline] |
Compares native thread IDs for inequality.
RWThreadId & RWThreadId::operator= | ( | const RWThreadId & | second | ) | [inline] |
Assignment operator.
bool RWThreadId::operator== | ( | const RWThreadId & | second | ) | const [inline] |
Compares native thread IDs for equality.
RWThreadId RWThreadId::self | ( | ) | [inline, static] |
Returns an RWThreadId for the current thread.
unsigned rwThreadHash | ( | const RWThreadId & | id | ) | [related] |
Use this function when a unique integer is required to identify a particular thread for hashing and trace/debug output purposes. The thread id value stored inside an RWThreadId instance should not be used directly, since some environments use a structure to represent a thread id.
RWThreadId rwThreadId | ( | ) | [related] |
The rwThreadId() function returns an RWThreadId instance containing the thread id value associated with the calling thread. This id value is assigned by the underlying threads system. You may query for the thread id of any thread, regardless of its method of creation. Use the rwThreadHash() function to convert a thread id to a unique integer for the purpose of producing trace output and hash-table indexing.
typedef unsigned RWThreadIdRep [related] |
The internal thread id representation.
typedef thread_t RWThreadIdRep [related] |
The internal thread id representation.
typedef pthread_t RWThreadIdRep [related] |
The internal thread id representation.
typedef unsigned RWThreadIdRep [related] |
The internal thread id representation.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.