C++ Based OPC UA Client/Server SDK  1.5.5.355

This class is used to manager a pool of threads. More...

#include <uathreadpool.h>

Public Member Functions

 UaThreadPool (OpcUa_UInt32 minThreads, OpcUa_UInt32 maxThreads)
 Create a thread pool object with the minimum number of threads passed in. More...
 
virtual ~UaThreadPool ()
 Destroys the thread pool object.
 
OpcUa_StatusCode addJob (UaThreadPoolJob *job, OpcUa_Boolean blockAtAdd=OpcUa_True, OpcUa_Boolean addToPool=OpcUa_False)
 Adds a job to be executed by the thread pool. More...
 

Detailed Description

This class is used to manager a pool of threads.

This class manages and recycles individual UaThread objects to help reduce thread creation costs in programs that use threads. It also ensures that a maximum number of threads is used to execute worker thread jobs. Jobs are passed in as UaThreadPoolJob.

If all threads of the thread pool are busy, the jobs are added to a job pool. Jobs from the job pool will be processed by the next available threads. The job pool size is four times the maximum numbers of threads in the thread pool.

During the creation of the thread pool a minimum and maximum number of threads is defined. The thread pool creates the minimum number of threads when it is created. It creates more threads if needed but not more than defined as maximum.

See UaThreadPoolJob for an example.

The default and copy constructor and the copy operator are private and not supported.

Constructor & Destructor Documentation

UaThreadPool::UaThreadPool ( OpcUa_UInt32  minThreads,
OpcUa_UInt32  maxThreads 
)

Create a thread pool object with the minimum number of threads passed in.

Parameters
[in]minThreadsthe minimum of threads to use.
[in]maxThreadsthe maximum of threads to use.

Member Function Documentation

OpcUa_StatusCode UaThreadPool::addJob ( UaThreadPoolJob job,
OpcUa_Boolean  blockAtAdd = OpcUa_True,
OpcUa_Boolean  addToPool = OpcUa_False 
)

Adds a job to be executed by the thread pool.

The thread pool executes the job in a worker thread and deletes the job after the execution. If all worker threads are active, this method adds the job to the job pool.

If the job pool is full, the method either blocks or return an error depending on the setting of blockAtAdd. If this parameter is not set, the method blocks as default behaviour.

Parameters
jobPointer to job base class. Job data is contained in derived class.
blockAtAddFlag indicating if the method should block if all worker threads are in use and the job pool is full.
addToPoolFlag indicating if the method should add the job to the job pool if all worker threads are in use.
Returns
OpcUa_Good if the job was successfully added, bad status if an error occurred in the addJob function

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