SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWThreadId Class Reference

A wrapper for platform-specific thread IDs. More...

#include <rw/sync/RWThreadId.h>

Public Member Functions

 RWThreadId ()
 
 RWThreadId (const RWThreadId &second)
 
 RWThreadId (const RWThreadIdRep &threadIdRep)
 
 RWThreadId (RWStaticCtor)
 
 ~RWThreadId ()
 
void clear ()
 
RWThreadIdRepgetRep () const
 
unsigned hash () const
 
bool isValid () const
 
 operator RWThreadIdRep & () const
 
bool operator!= (const RWThreadId &second) const
 
RWThreadIdoperator= (const RWThreadId &second)
 
bool operator== (const RWThreadId &second) const
 

Static Public Member Functions

static bool isSelf (const RWThreadId &id)
 
static RWThreadId self ()
 

Related Symbols

(Note that these are not member symbols.)

unsigned rwThreadHash (const RWThreadId &id)
 
RWThreadId rwThreadId ()
 
typedef pthread_t RWThreadIdRep
 
typedef thread_t RWThreadIdRep
 
typedef unsigned RWThreadIdRep
 

Detailed Description

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 an integer 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.

Example
#include <rw/thread/RWThreadFunction.h>
#include <rw/sync/RWThreadId.h>
void whoamiReally() {
std::cout << "My thread ID is " << rwThreadHash(myID) << std::endl;
}
int main() {
RWThread t1, t2, t3;
(t1 = RWThreadFunction::make(whoamiReally)).start();
(t2 = RWThreadFunction::make(whoamiReally)).start();
(t3 = RWThreadFunction::make(whoamiReally)).start();
t1.join();
t2.join();
t3.join();
return 0;
}
void join(void)
static RWThreadFunction make()
A wrapper for platform-specific thread IDs.
Definition RWThreadId.h:169
RWThreadId rwThreadId()
Definition RWThreadId.h:450
unsigned rwThreadHash(const RWThreadId &id)
Definition RWThreadId.h:437
Handle class for a threaded runnable object.
Definition RWThread.h:77

OUTPUT:

My thread ID is 4
My thread ID is 5
My thread ID is 6
See also
rwThreadId(), rwThreadHash(), rwThread(), RWRunnableHandle

Constructor & Destructor Documentation

◆ RWThreadId() [1/4]

RWThreadId::RWThreadId ( )
inline

Creates an RWThreadId object not associated with any thread.

◆ RWThreadId() [2/4]

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.

Note
This constructor must be used only for static instances. Use of this constructor with an automatically or dynamically allocated instance may produce unpredictable behavior.

◆ RWThreadId() [3/4]

RWThreadId::RWThreadId ( const RWThreadIdRep & threadIdRep)
inline

Creates an RWThreadId object directly from a native thread ID.

◆ RWThreadId() [4/4]

RWThreadId::RWThreadId ( const RWThreadId & second)
inline

Copy constructor.

◆ ~RWThreadId()

RWThreadId::~RWThreadId ( )
inline

Destructor.

Member Function Documentation

◆ clear()

void RWThreadId::clear ( )
inline

Clears the native thread ID so it won't match other native IDs.

◆ getRep()

RWThreadIdRep * RWThreadId::getRep ( ) const
inline

Returns the address of the native thread ID member.

◆ hash()

unsigned RWThreadId::hash ( ) const
inline

Returns a hash of the thread ID.

◆ isSelf()

bool RWThreadId::isSelf ( const RWThreadId & id)
inlinestatic

Returns true if id matches the thread ID of the currently running thread; otherwise, returns false.

◆ isValid()

bool RWThreadId::isValid ( ) const
inline

Returns true if this thread ID was constructed or assigned from a native thread instance, otherwise false.

◆ operator RWThreadIdRep &()

RWThreadId::operator RWThreadIdRep & ( ) const
inline

Returns a reference to the native thread ID.

◆ operator!=()

bool RWThreadId::operator!= ( const RWThreadId & second) const
inline

Compares native thread IDs for inequality.

◆ operator=()

RWThreadId & RWThreadId::operator= ( const RWThreadId & second)
inline

Assignment operator.

◆ operator==()

bool RWThreadId::operator== ( const RWThreadId & second) const
inline

Compares native thread IDs for equality.

◆ self()

RWThreadId RWThreadId::self ( )
inlinestatic

Returns an RWThreadId for the current thread.

Friends And Related Symbol Documentation

◆ rwThreadHash()

unsigned rwThreadHash ( const RWThreadId & id)
related

Use this function when an 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.

See also
RWThreadId

◆ rwThreadId()

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.

See also
RWThreadId, rwThreadHash()

◆ RWThreadIdRep [1/3]

typedef pthread_t RWThreadIdRep
related

The internal thread id representation.

Condition:
This type is used for build configurations based on POSIX threads.

◆ RWThreadIdRep [2/3]

typedef thread_t RWThreadIdRep
related

The internal thread id representation.

Condition:
This type is used for build configurations based on Solaris threads.

◆ RWThreadIdRep [3/3]

typedef unsigned RWThreadIdRep
related

The internal thread id representation.

Condition:
This type is used for build configurations based on Win32 threads.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.