Falcon::SysThread Class Reference

System Thread class. More...

#include <mt.h>

Inheritance diagram for Falcon::SysThread:

Inheritance graph
[legend]

List of all members.

Public Member Functions

void attachToCurrent ()
 Makes this object to represent currently running system thread.
void detach ()
 Detach this thread.
void disengage ()
 Dispose of this object without modifying the underlying system data.
bool equal (const SysThread *th1) const
 Returns true if two threads represents the same low level threads.
uint64 getID ()
 Returns the current thread ID.
bool isCurrentThread ()
 Returns true if the thread is currently running.
bool join (void *&result)
 Join this thread.
virtual void * run ()
 Run method.
bool start ()
 Launches a new instance of this thread with default parameters.
bool start (const ThreadParams &params)
 Launches a new instance of this thread.
SYSTH_DATAsysdata () const
 SysThread (Runnable *r=0)

Static Public Member Functions

static bool equal (const SysThread *th1, const SysThread *th2)
static uint64 getCurrentID ()
 Returns the thread ID of the running thread.
static void * RunAThread (void *)

Protected Member Functions

virtual ~SysThread ()

Protected Attributes

Runnablem_runnable


Detailed Description

System Thread class.

Can be used both to run a Runnable class instance, or to run its own virtual run method.

This class is called SysThread to distinguish it from the higher level Thread. This class just encapsulates the system threading, wheres Thread gives more multithreading programming high level support, as interrupt management and multiple object wait.

Notice that we don't have a stop() or cancel() or interrupt() method in this class. This is because all stop requests are handled at higher level, by the threads interested in VM operations (so that they can be handled i.e. by the scripts). MS-Windows doesn't provide a cancelation protocol, while POSIX cancelation system doesn't allow for handling of the cancelation event (the semantic is such that cancelation of I/O blocking operations must be honored ASAP, with at least a small control on cleanup). Both ways to do the thing (i.e. none or too much) aren't good for the code we're writing above this class, so we just drop this feature and re-implement cancelation requests at higher level, preventing - controlling blocking I/O.


Constructor & Destructor Documentation

virtual Falcon::SysThread::~SysThread (  )  [protected, virtual]

Falcon::SysThread::SysThread ( Runnable r = 0  ) 


Member Function Documentation

void Falcon::SysThread::attachToCurrent (  ) 

Makes this object to represent currently running system thread.

This must be called after the constructor and before start().

void Falcon::SysThread::detach (  ) 

Detach this thread.

After this call, the thread will take care of destroying itself at termination. Joining threads will receive an unjoinable exception.

Notice that if the run() return value is dynamically allocate, it will be leaked, so this method should be called only for threads not returning any value.

After this call, this instance must be considered invalid.

Note:
A SysThread must terminate either because a detach or with a join. The destroyer cannot be called directly (this means you can't create a SysThread instance in the stack).

void Falcon::SysThread::disengage (  ) 

Dispose of this object without modifying the underlying system data.

static bool Falcon::SysThread::equal ( const SysThread th1,
const SysThread th2 
) [inline, static]

References equal().

bool Falcon::SysThread::equal ( const SysThread th1  )  const

Returns true if two threads represents the same low level threads.

Referenced by equal().

static uint64 Falcon::SysThread::getCurrentID (  )  [static]

Returns the thread ID of the running thread.

On POSIX systems, it returns the value of an unique value associated with each thread; on MS-Windows systems returns the system Thread ID.

uint64 Falcon::SysThread::getID (  ) 

Returns the current thread ID.

On POSIX systems, it returns the value of an unique value associated with each thread; on MS-Windows systems returns the system Thread ID.

bool Falcon::SysThread::isCurrentThread (  ) 

Returns true if the thread is currently running.

bool Falcon::SysThread::join ( void *&  result  ) 

Join this thread.

Wait for this thread to terminate, and return the value returned by run(). After join has returned, this thread cannot be used anymore (it is virtually destroyed).

Note:
A SysThread must terminate either because a detach or with a join. The destroyer cannot be called directly (this means you can't create a SysThread instance in the stack).
Parameters:
result The output of the run() method of this thread.
Returns:
false if the thread is not joinable, true if it has been joined.

virtual void* Falcon::SysThread::run (  )  [virtual]

Run method.

The base class method just runs the runnable's run(). It asserts( or crashes) if the runnable has not been set in the first place.

Subclasses are free to set everything they want as the run method.

static void* Falcon::SysThread::RunAThread ( void *   )  [static]

bool Falcon::SysThread::start (  )  [inline]

Launches a new instance of this thread with default parameters.

Only one start can be performed for a thread. Trying to execute start more than once will fail.

References start().

Referenced by start().

bool Falcon::SysThread::start ( const ThreadParams params  ) 

Launches a new instance of this thread.

Only one start can be performed for a thread. Trying to execute start more than once will fail.

SYSTH_DATA* Falcon::SysThread::sysdata (  )  const [inline]


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Mon Oct 19 10:11:47 2009 for Falcon_Core by  doxygen 1.5.8