Module: Threads Package: Synchronization
Does not inherit
clear() getRep() hash() |
isSelf() isValid() operator!=() |
operator=() operator==() RWThreadId() |
RWThreadIdRep&() self() ~RWThreadId() |
#include <rw/sync/RWThreadId.h>
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, that is associated with the current thread of execution. The rwThreadHash() function should be used to retrieve a unique integer value associated with a thread id for output or debugging purposes. You should 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; } /* * OUTPUT: * My native thread ID is 4 My native thread ID is 5 My native thread ID is 6 * */
typedef unsigned RWThreadIdRep; // Single-Threaded typedef pthread_t RWThreadIdRep; // POSIX typedef thread_t RWThreadIdRep; // SOLARIS typedef unsigned RWThreadIdRep; // Win32 with Microsoft
static bool isSelf(const RWThreadId& id);
Returns true if id matches the thread ID of the currently running thread; otherwise, returns false.
static RWThreadId self();
Returns an RWThreadId for the current thread.
RWThreadId();
Creates an RWThreadId object not associated with any thread.
RWThreadId(const RWThreadIdRep& threadId);
Creates an RWThreadId object directly from a native thread ID.
~RWThreadId();
Destructor.
RWThreadId& operator=(const RWThreadId& second);
Assignment operator.
bool operator==(const RWThreadId& second) const;
Compares native thread IDs for equality.
bool operator!=(const RWThreadId& second) const;
Compares native thread IDs for inequality.
operator RWThreadIdRep&() const;
Returns a reference to the native thread ID.
void clear();
Clears the native thread ID so it won't match other native IDs.
RWThreadIdRep* getRep() const;
Returns the address of the native thread ID member.
unsigned hash() const;
Returns a hash of the thread ID.
bool isValid() const;
Returns true if this thread ID was constructed or assigned from a native thread instance.
rwThreadId(), rwThreadHash(), rwThread(), RWRunnableHandle
© 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.