class
ThreadPool
Class that maintains a pool of threads we can easily retrieve and use for any task.
This saves on the cost of creating and destroying threads.
Public
Constructors
ThreadPool
Constructs a new thread pool
- threadCapacity
- Default thread capacity, the pool will always try to keep this many threads available.
- idleTimeout
- (optional) How many seconds do threads need to be idle before we remove them from the pool.
Methods
~ThreadPool
Run
Find an unused thread (or creates a new one) and runs the specified worker method on it.
- name
- A name you may use for more easily identifying the thread.
- workerMethod
- The worker method to be called by the thread.
Returns: A thread handle you may use for monitoring the thread execution.
StopAll
Stops all threads and destroys them.
Caller must ensure each threads worker method returns otherwise this will never return.
ClearUnused
Clear any unused threads that are over the capacity.
GetNumActive
Returns the number of running threads in the pool.
GetNumAllocated
Returns the total number of created threads in the pool (both running and unused).
staticInstance
Returns a reference to the module instance.
Module has to have been started up first otherwise an exception will be thrown.
staticInstancePtr
Returns a pointer to the module instance.
Module has to have been started up first otherwise an exception will be thrown.
staticShutDown
Shuts down this module and frees any resources it is using.
staticIsStarted
Query if the module has been started.
Protected
Methods
CreateThread
Creates a new thread to be used by the pool.
GetThread
Returns the first unused thread if one exists, otherwise creates a new one.
- name
- Name to assign the thread.
~Module<T>
OnStartUp
Override if you want your module to be notified once it has been constructed and started.
OnShutDown
Override if you want your module to be notified just before it is deleted.
staticInstanceInternal
Returns a singleton instance of this module.
Fields
mThreads
mDefaultCapacity
mIdleTimeout
mAge
unused check counter