#include <D:/Temp/vs/gal/source/MultithreadingAlgorithm.h>
Inherits Algorithm::GaBaseAlgorithm.
Inherited by Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm, and Algorithm::SimpleAlgorithms::GaSimpleAlgorithm.
Public Member Functions | |
GAL_API | GaMultithreadingAlgorithm (const GaMultithreadingAlgorithmParams ¶meters) |
This constructor initializes control structures with user-defined parameters. | |
virtual GAL_API | ~GaMultithreadingAlgorithm () |
Destructors releases acquired resources such as threads and synchronization objects and memory used by control structures. | |
virtual GAL_API void GACALL | SetAlgorithmParameters (const GaAlgorithmParams ¶meters) |
This method should be called from classes that inherit this class when user changes algorithm parameters. It updates structures which control multithreading execution. | |
virtual GAL_API bool GACALL | WaitForThreads () |
This method waits for control and working thread to finish their execution. | |
Protected Member Functions | |
virtual void GACALL | BeforeWorkers () |
This method is called before workers execute their steps. It is executed in control thread context. | |
virtual void GACALL | WorkStep (int workerId) |
After control thread executes BeforeWork method, working threads starts execution and steps in this method. Working threads get their identification numbers which are assigned sequentially to them. | |
virtual void GACALL | AfterWorkers () |
This method is called after workers finish their steps. It is executed in control thread context. | |
virtual bool GACALL | OnStart () |
This method starts control and working threads. | |
virtual bool GACALL | OnStop () |
This method waits for control and working thread to finish their execution. | |
virtual bool GACALL | OnPause () |
This method waits for control and working thread to finish their execution. | |
virtual bool GACALL | OnResume () |
This method starts control and working threads. | |
virtual GAL_API void GACALL | ControlFlow () |
This method implements work flow of control thread. | |
virtual GAL_API void GACALL | WorkFlow () |
This method implements work flow of working thread. | |
virtual GAL_API bool GACALL | StartThreads () |
This method starts control and working threads. | |
Protected Attributes | |
SysSemaphoreObject | _workerForkSync |
Object for synchronization of working step start. | |
SysEventObject | _workerJoinSync |
Object for synchronization of worker threads with control thread after end of work step. | |
int | _workersThreadIn |
Number of workers thread currently executing working section of code. | |
bool | _parametersChange |
This flag indicates that user has changed some aspect of the algorithm, but algorithm didn't refresh its control structures. | |
int | _numberOfThreads |
Number of threads which are used by algorithm (working and control threads). | |
volatile int | _workerIdCounter |
This attribute is used for assigning identifiers to working threads when algorithm starts execution. | |
GaThread ** | _threads |
Array of threads which are used by the algorithm (working and control threads). | |
Static Private Member Functions | |
static ThreadFunctionReturn GACALL | ControlFlowWrapper (GaThread *thread, void *params) |
This method is used as wrapper for control flow method and is used when algorithm starts control thread. | |
static ThreadFunctionReturn GACALL | WorkFlowWrapper (GaThread *thread, void *params) |
This method is used as wrapper for working flow method and is used when algorithm starts working thread. |
This class has no built-in synchronizator, so LOCK_OBJECT
and LOCK_THIS_OBJECT
macros cannot be used with instances of this class, but all public method and operators are thread-safe.
Algorithm::GaMultithreadingAlgorithm::GaMultithreadingAlgorithm | ( | const GaMultithreadingAlgorithmParams & | parameters | ) |
This constructor initializes control structures with user-defined parameters.
parameters | reference to algorithm parameters. |
Algorithm::GaMultithreadingAlgorithm::~GaMultithreadingAlgorithm | ( | ) | [virtual] |
Destructors releases acquired resources such as threads and synchronization objects and memory used by control structures.
void Algorithm::GaMultithreadingAlgorithm::SetAlgorithmParameters | ( | const GaAlgorithmParams & | parameters | ) | [virtual] |
This method should be called from classes that inherit this class when user changes algorithm parameters. It updates structures which control multithreading execution.
More details are given in specification of GaAlgorithm::SetAlgorithmParameters method.
This method is thread-safe.
Implements Algorithm::GaAlgorithm.
Reimplemented in Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm, and Algorithm::SimpleAlgorithms::GaSimpleAlgorithm.
bool Algorithm::GaMultithreadingAlgorithm::WaitForThreads | ( | ) | [virtual] |
This method waits for control and working thread to finish their execution.
true
if ther were no errors during waiting.virtual void GACALL Algorithm::GaMultithreadingAlgorithm::BeforeWorkers | ( | ) | [inline, protected, virtual] |
This method is called before workers execute their steps. It is executed in control thread context.
Reimplemented in Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm, and Algorithm::SimpleAlgorithms::GaSimpleAlgorithm.
virtual void GACALL Algorithm::GaMultithreadingAlgorithm::WorkStep | ( | int | workerId | ) | [inline, protected, virtual] |
After control thread executes BeforeWork method, working threads starts execution and steps in this method. Working threads get their identification numbers which are assigned sequentially to them.
workerId | identification number of working thread |
Reimplemented in Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm, and Algorithm::SimpleAlgorithms::GaSimpleAlgorithm.
virtual void GACALL Algorithm::GaMultithreadingAlgorithm::AfterWorkers | ( | ) | [inline, protected, virtual] |
This method is called after workers finish their steps. It is executed in control thread context.
Reimplemented in Algorithm::SimpleAlgorithms::GaIncrementalAlgorithm, and Algorithm::SimpleAlgorithms::GaSimpleAlgorithm.
virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnStart | ( | ) | [inline, protected, virtual] |
virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnStop | ( | ) | [inline, protected, virtual] |
This method waits for control and working thread to finish their execution.
Implements Algorithm::GaBaseAlgorithm.
virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnPause | ( | ) | [inline, protected, virtual] |
This method waits for control and working thread to finish their execution.
Implements Algorithm::GaBaseAlgorithm.
virtual bool GACALL Algorithm::GaMultithreadingAlgorithm::OnResume | ( | ) | [inline, protected, virtual] |
void Algorithm::GaMultithreadingAlgorithm::ControlFlow | ( | ) | [protected, virtual] |
This method implements work flow of control thread.
void Algorithm::GaMultithreadingAlgorithm::WorkFlow | ( | ) | [protected, virtual] |
This method implements work flow of working thread.
bool Algorithm::GaMultithreadingAlgorithm::StartThreads | ( | ) | [protected, virtual] |
This method starts control and working threads.
true
if all threads are started successafully.ThreadFunctionReturn Algorithm::GaMultithreadingAlgorithm::ControlFlowWrapper | ( | GaThread * | thread, | |
void * | params | |||
) | [static, private] |
This method is used as wrapper for control flow method and is used when algorithm starts control thread.
thread | pointer to control thread. | |
params | pointer to parameters which are passed by algorithm to the control thread. |
ThreadFunctionReturn Algorithm::GaMultithreadingAlgorithm::WorkFlowWrapper | ( | GaThread * | thread, | |
void * | params | |||
) | [static, private] |
This method is used as wrapper for working flow method and is used when algorithm starts working thread.
thread | pointer to working thread. | |
params | pointer to parameters which are passed by algorithm to the working thread. |
SysSemaphoreObject Algorithm::GaMultithreadingAlgorithm::_workerForkSync [protected] |
Object for synchronization of working step start.
SysEventObject Algorithm::GaMultithreadingAlgorithm::_workerJoinSync [protected] |
Object for synchronization of worker threads with control thread after end of work step.
int Algorithm::GaMultithreadingAlgorithm::_workersThreadIn [protected] |
Number of workers thread currently executing working section of code.
bool Algorithm::GaMultithreadingAlgorithm::_parametersChange [protected] |
This flag indicates that user has changed some aspect of the algorithm, but algorithm didn't refresh its control structures.
int Algorithm::GaMultithreadingAlgorithm::_numberOfThreads [protected] |
Number of threads which are used by algorithm (working and control threads).
volatile int Algorithm::GaMultithreadingAlgorithm::_workerIdCounter [protected] |
This attribute is used for assigning identifiers to working threads when algorithm starts execution.
GaThread** Algorithm::GaMultithreadingAlgorithm::_threads [protected] |
Array of threads which are used by the algorithm (working and control threads).