Threading::GaThread Class Reference

GaThread class controls system threads. It wraps system specific control of threading. This class has built-in synchronizator so it is allowed to use LOCK_OBJECT and LOCK_THIS_OBJECT macros with instances of this class. More...

#include <D:/Temp/vs/gal/source/Threading.h>

List of all members.

Public Member Functions

GAL_API GaThread (const GaThreadParameter &parameters, bool started)
 Initializes thread object and stores thread parameters. If user specified, thread can be started automatically when object is created.
GAL_API ~GaThread ()
 Stops thread if it is running and releases system object and closes handles to it.
GAL_API bool GACALL Start ()
 Method starts execution of the thread or resumes execution if it was suspended. If thread already running or system is unable to start/resume thread call fails and method returns false.
GAL_API bool GACALL Pause ()
 Method suspends thread execution if it is running. If thread is stopped or system cannot suspend thread, call fails and method returns false. Pause method is intended only for debugging purposes.
GAL_API bool GACALL Abort ()
 Method stops execution of thread forcibly. Calling this method can cause problems thread cannot release acquired resources properly and do necessary cleanups.
GAL_API bool GACALL Join ()
 Suspends execution of thread from which it was called until thread which is managed by this instance of GaThread class finish execution.
GaThreadStatus GACALL Status ()
 This method is thread-safe.
ThreadID GACALL GetId ()
 This method is thread-safe.

Static Private Member Functions

static ThreadFunctionReturn APICALL ThreadFunctionWraper (GaThread *thread)
 This method is used as entry point of new thread. Operating system calls this method when it starts thread. After that, when thread enters ThreadFunctionWrapper it calls user entry point which is specified in thread parameters.

Private Attributes

GaThreadStatus _status
 This attribute holds running status of the thread.
SystemThread _thread
 System specific the thread object or handle to it.
ThreadID _id
 stores identification number of thread if it is running or it is suspended.
GaThreadParameter _parameters
 User defined information (thread's entry point and custom parameters passed to the thread) needed to start thread.


Detailed Description

GaThread class controls system threads. It wraps system specific control of threading. This class has built-in synchronizator so it is allowed to use LOCK_OBJECT and LOCK_THIS_OBJECT macros with instances of this class.


Constructor & Destructor Documentation

Threading::GaThread::GaThread ( const GaThreadParameter parameters,
bool  started 
)

Initializes thread object and stores thread parameters. If user specified, thread can be started automatically when object is created.

Parameters:
parameters thread parameters (entry point and pointer to custom parameters passed to the thread).
started if this parameter is set to true then thread start execution immediately.

Threading::GaThread::~GaThread (  ) 

Stops thread if it is running and releases system object and closes handles to it.


Member Function Documentation

bool Threading::GaThread::Start (  ) 

Method starts execution of the thread or resumes execution if it was suspended. If thread already running or system is unable to start/resume thread call fails and method returns false.

This method is thread-safe.

Returns:
Method returns true if thread is started/resumed successfully. If thread was in running state or system is unable to start/resume thread method returns false.

bool Threading::GaThread::Pause (  ) 

Method suspends thread execution if it is running. If thread is stopped or system cannot suspend thread, call fails and method returns false. Pause method is intended only for debugging purposes.

This method is not implemented on *nix systems.

This method is thread-safe.

Returns:
Method returns true if thread is suspended successfully. If thread was stopped or system couldn't suspend thread method returns false.

bool Threading::GaThread::Abort (  ) 

Method stops execution of thread forcibly. Calling this method can cause problems thread cannot release acquired resources properly and do necessary cleanups.

This method is thread-safe.

Returns:
Method returns true if thread is stopped successfully. If thread was stopped or system couldn't stop thread method returns false.

bool Threading::GaThread::Join (  ) 

Suspends execution of thread from which it was called until thread which is managed by this instance of GaThread class finish execution.

This method is thread-safe.

Returns:
Method returns true if waiting has finished successfully. If there was an error method returns false.

GaThreadStatus GACALL Threading::GaThread::Status (  )  [inline]

This method is thread-safe.

Returns:
Method returns current status of the thread.

ThreadID GACALL Threading::GaThread::GetId (  )  [inline]

This method is thread-safe.

Returns:
Method returns identification number of thread if it is running or suspended. If thread is stopped, method returns 0.

ThreadFunctionReturn Threading::GaThread::ThreadFunctionWraper ( GaThread thread  )  [static, private]

This method is used as entry point of new thread. Operating system calls this method when it starts thread. After that, when thread enters ThreadFunctionWrapper it calls user entry point which is specified in thread parameters.

Parameters:
 pointer to object which manages new thread.
Returns:
Method returns result of user defined thread's entry point function when thread finishes its execution.


Member Data Documentation

This attribute holds running status of the thread.

System specific the thread object or handle to it.

stores identification number of thread if it is running or it is suspended.

User defined information (thread's entry point and custom parameters passed to the thread) needed to start thread.


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

Genetic Algorithm Library
Coolsoft Software Development