#include <rw/sync/RWThreadId.h>
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.h++ 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 which Threads.h++ 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 DWORD RWThreadIdRep; // Win32 with Borland typedef pthread_t RWThreadIdRep; // POSIX typedef thread_t RWThreadIdRep; // SOLARIS typedef TID RWThreadIdRep; // OS/2 typedef unsigned RWThreadIdRep; // Win32 with Microsoft
RWThreadId(void);
Creates an RWThreadId object not associated with any thread.
RWThreadId(const RWThreadIdRep& threadId);
Creates an RWThreadId object directly from a native thread ID.
RWThreadId& operator=(const RWThreadId& second);
Assignment operator.
RWThreadIdRep* operator&(void) const;
Returns the address of the native thread ID member.
RWBoolean operator==(const RWThreadId& second) const;
Compares native thread IDs for equality.
RWBoolean operator!=(const RWThreadId& second) const;
Compares native thread IDs for inequality.
operator RWThreadIdRep&() const;
Returns a reference to the native thread ID.
void clear(vod);
Clears the native thread ID so it won't match other native IDs.
unsigned hash(void) const;
Returns a hash of the thread ID.
rwThreadId, rwThreadHash, rwThread, RWRunnableHandle
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.