C++ Based OPC UA Client/Server SDK
1.6.5.478
|
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... | |
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.
UaThreadPool::UaThreadPool | ( | OpcUa_UInt32 | minThreads, |
OpcUa_UInt32 | maxThreads | ||
) |
Create a thread pool object with the minimum number of threads passed in.
[in] | minThreads | the minimum of threads to use. |
[in] | maxThreads | the maximum of threads to use. |
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.
job | Pointer to job base class. Job data is contained in derived class. |
blockAtAdd | Flag indicating if the method should block if all worker threads are in use and the job pool is full. |
addToPool | Flag indicating if the method should add the job to the job pool if all worker threads are in use. |