Server
API Reference Guide
Product Documentation:

Rogue Wave Server
Documentation Home
List of all members | Public Member Functions | Static Public Member Functions | Friends
IlsThread Class Reference

API FOR ADVANCED USERS – A thread object is used to create a new thread of execution. More...

#include <ilserver/ilthread.h>

Inheritance diagram for IlsThread:
IlsMTBase

Public Member Functions

 IlsThread (IlsThreadStartFunc, IlsAny=0, int=0)
 Constructor. More...
 
virtual ~IlsThread ()
 Destructor. More...
 
void addTerminatedCallback (IlsThreadTerminatedFunc, IlsAny=0)
 This member function adds a callback which is invoked when a thread exits normally. More...
 
IlsThreadId getIdentifier () const
 This member function returns an operating system-dependent value which may be the address of the thread or the thread identifier.
 
IlsBoolean isAlive ()
 This member function tests the status of the thread. It returns IlsTrue if the thread was created successfully and has not yet exited. More...
 
void join ()
 This member function is equivalent to the static Join().
 
void removeTerminatedCallback (IlsThreadTerminatedFunc, IlsAny=0)
 This member function removes the thread-terminated callback that was added by a call to addTerminatedCallback().
 
IlsBoolean wasCreated ()
 This member function tests the status of the thread. It returns IlsFalse if the thread was not created successfully.
 
- Public Member Functions inherited from IlsMTBase
virtual ~IlsMTBase ()
 This is the public virtual destructor for this class.
 
virtual IlsThreadObjectName getName () const
 This member function returns the name of an object. More...
 

Static Public Member Functions

static void ExitCurrentThread ()
 This static member function terminates the calling thread without returning from the start procedure.
 
static IlsThreadId getCurrentIdentifier ()
 This static member function returns the identifier of the current thread. More...
 
static void Join (IlsThread *t)
 This static member function can be used to keep the calling thread waiting for the termination of a given thread.
 
static IlsBoolean MtSafe ()
 This static member function returns IlsTrue if the library supports multithreading. Otherwise, it returns IlsFalse.
 
static void Yield ()
 This static member function allows for another thread with the same priority or greater to be scheduled (if there are any waiting). More...
 

Friends

ostream & operator<< (ostream &, const IlsThread &)
 This operator prints the name of the object to the output stream. More...
 

Detailed Description

API FOR ADVANCED USERS – A thread object is used to create a new thread of execution.

Library: server
and mvcomp

There is no thread object associated with the main thread. Thread classes are special classes in that the life span of the thread can outlive the life of the thread object.

See also
IlsBarrier, IlsCond, IlsSafeMutex, IlsThreadContext, IlsUnsafeMutex.

Constructor & Destructor Documentation

◆ IlsThread()

IlsThread::IlsThread ( IlsThreadStartFunc  ,
IlsAny  = 0,
int  = 0 
)

Constructor.

The constructor of a thread takes the start procedure as its first argument. This procedure is the one that is run when the thread starts.

The start function for a thread takes a single parameter as its argument, which is the second argument to the constructor. This argument will normally be cast to the correct type within the start function.

The third optional argument of the thread constructor is the stack size for the thread being created. We recommend that you supply the stack size. If you do not supply it, a platform-dependent value will be used. It should not be assumed that stack overflow in a thread will be detected by the underlying operating system.

Note
Creating a thread does not mean that the thread will be run immediately. The execution of a thread depends on the platform on which the program is running.

◆ ~IlsThread()

virtual IlsThread::~IlsThread ( )
virtual

Destructor.

Destroying a thread object does not destroy the thread. In the same way, a thread may exit, and hence no longer be valid even though the thread object still exists. The member function isAlive() can be used to check whether the system thread is still running.

Member Function Documentation

◆ addTerminatedCallback()

void IlsThread::addTerminatedCallback ( IlsThreadTerminatedFunc  ,
IlsAny  = 0 
)

This member function adds a callback which is invoked when a thread exits normally.

In this case, all the registered callbacks are called (in an unspecified order). The second argument is the one that is passed to the callback(s).

◆ getCurrentIdentifier()

static IlsThreadId IlsThread::getCurrentIdentifier ( )
static

This static member function returns the identifier of the current thread.

Since it can be called a very large number of times, this member function is inline. Thus, the thread library adds no extra overhead when compared to the native library.

◆ isAlive()

IlsBoolean IlsThread::isAlive ( )

This member function tests the status of the thread. It returns IlsTrue if the thread was created successfully and has not yet exited.

This does not mean that the thread has been scheduled yet nor that the start function has been executed.

◆ Yield()

static void IlsThread::Yield ( )
static

This static member function allows for another thread with the same priority or greater to be scheduled (if there are any waiting).

The exact behavior of this call depends on the machine used, and therefore on the scheduling policy of the underlying operating system.

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  ,
const IlsThread  
)
friend

This operator prints the name of the object to the output stream.

This uses the method getName() to get the name of the thread. If the method getName() returns 0 then it uses the thread id, retrieved by the method getIdentifier().