ITK
4.9.0
Insight Segmentation and Registration Toolkit
|
#include <itkThreadPool.h>
Thread pool manages the threads for itk.
Thread pool is called and initialized from within the MultiThreader. Initially the thread pool is started with zero threads. Threads are added as job(s) are submitted to the thread pool and if it cannot be executed right away. For example : If the thread pool has three threads and all are busy. If a new job is submitted to the thread pool, the thread pool checks to see if any threads are free. If not, it adds a new thread and executed the job right away. The ThreadJob class is used to submit jobs to the thread pool. The ThreadJob's necessary members need to be set and then the ThreadJob can be passed to the ThreaadPool by calling its AssignWork Method which returns the thread id on which the job is being executed. One can then wait for the job using the thread id and calling the WaitForJob method on the thread pool.
Definition at line 72 of file itkThreadPool.h.
Classes | |
class | ThreadProcessIdentifiers |
class | ThreadSemaphorePair |
Public Types | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef ThreadPool | Self |
typedef Object | Superclass |
typedef unsigned int | ThreadCountType |
typedef ThreadJob::JobIdType | ThreadJobIdType |
typedef int | ThreadTimeType |
Public Types inherited from itk::Object | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef Object | Self |
typedef LightObject | Superclass |
Public Types inherited from itk::LightObject | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef LightObject | Self |
Public Member Functions | |
ThreadProcessIdType | AssignWork (ThreadJob worker) |
virtual const char * | GetNameOfClass () const |
void | InitializeThreads (ThreadCountType maxThreads) |
bool | WaitForJobOnThreadHandle (ThreadProcessIdType handle) |
Public Member Functions inherited from itk::Object | |
unsigned long | AddObserver (const EventObject &event, Command *) |
unsigned long | AddObserver (const EventObject &event, Command *) const |
virtual LightObject::Pointer | CreateAnother () const override |
virtual void | DebugOff () const |
virtual void | DebugOn () const |
Command * | GetCommand (unsigned long tag) |
bool | GetDebug () const |
MetaDataDictionary & | GetMetaDataDictionary () |
const MetaDataDictionary & | GetMetaDataDictionary () const |
virtual ModifiedTimeType | GetMTime () const |
virtual const TimeStamp & | GetTimeStamp () const |
bool | HasObserver (const EventObject &event) const |
void | InvokeEvent (const EventObject &) |
void | InvokeEvent (const EventObject &) const |
virtual void | Modified () const |
virtual void | Register () const override |
void | RemoveAllObservers () |
void | RemoveObserver (unsigned long tag) |
void | SetDebug (bool debugFlag) const |
void | SetMetaDataDictionary (const MetaDataDictionary &rhs) |
virtual void | SetReferenceCount (int) override |
virtual void | UnRegister () const noexceptoverride |
virtual void | SetObjectName (std::string _arg) |
virtual const std::string & | GetObjectName () const |
Public Member Functions inherited from itk::LightObject | |
virtual void | Delete () |
virtual int | GetReferenceCount () const |
itkCloneMacro (Self) | |
void | Print (std::ostream &os, Indent indent=0) const |
Static Public Member Functions | |
static Pointer | GetInstance () |
static Pointer | New () |
Static Public Member Functions inherited from itk::Object | |
static bool | GetGlobalWarningDisplay () |
static void | GlobalWarningDisplayOff () |
static void | GlobalWarningDisplayOn () |
static Pointer | New () |
static void | SetGlobalWarningDisplay (bool flag) |
Static Public Member Functions inherited from itk::LightObject | |
static void | BreakOnError () |
static Pointer | New () |
Protected Member Functions | |
ThreadPool () | |
virtual | ~ThreadPool () |
Protected Member Functions inherited from itk::Object | |
Object () | |
bool | PrintObservers (std::ostream &os, Indent indent) const |
virtual void | PrintSelf (std::ostream &os, Indent indent) const override |
virtual void | SetTimeStamp (const TimeStamp &time) |
virtual | ~Object () |
Protected Member Functions inherited from itk::LightObject | |
virtual LightObject::Pointer | InternalClone () const |
LightObject () | |
virtual void | PrintHeader (std::ostream &os, Indent indent) const |
virtual void | PrintTrailer (std::ostream &os, Indent indent) const |
virtual | ~LightObject () |
Private Types | |
enum | { JOB_THREADHANDLE_JUST_ADDED =-3, JOB_THREADHANDLE_IS_FREE =-2, JOB_THREADHANDLE_IS_DONE =-1 } |
typedef std::pair < ThreadJobIdType, ThreadJob > | ThreadJobContainerPairType |
typedef std::map < ThreadJobIdType, ThreadJob > | ThreadJobContainerType |
typedef std::set< ThreadJobIdType > | ThreadJobIdsContainerType |
typedef std::set < ThreadProcessIdType > | ThreadProcessIdContainerType |
Private Member Functions | |
ThreadPool & | operator= (ThreadPool const &) ITK_DELETE_FUNCTION |
ThreadPool (ThreadPool const &) ITK_DELETE_FUNCTION | |
Private Attributes | |
bool | m_ExceptionOccurred |
unsigned int | m_IdCounter |
bool | m_ScheduleForDestruction |
ThreadCountType | m_ThreadCount |
ThreadProcessIdContainerType | m_ThreadHandles |
ThreadJobContainerType | m_WorkerQueue |
Additional Inherited Members | |
Protected Attributes inherited from itk::LightObject | |
AtomicInt< int > | m_ReferenceCount |
typedef SmartPointer<const Self> itk::ThreadPool::ConstPointer |
Definition at line 80 of file itkThreadPool.h.
typedef SmartPointer< Self > itk::ThreadPool::Pointer |
Definition at line 79 of file itkThreadPool.h.
typedef ThreadPool itk::ThreadPool::Self |
Standard class typedefs.
Definition at line 77 of file itkThreadPool.h.
typedef Object itk::ThreadPool::Superclass |
Definition at line 78 of file itkThreadPool.h.
typedef unsigned int itk::ThreadPool::ThreadCountType |
Definition at line 84 of file itkThreadPool.h.
|
private |
Definition at line 157 of file itkThreadPool.h.
|
private |
Definition at line 155 of file itkThreadPool.h.
|
private |
Definition at line 159 of file itkThreadPool.h.
Definition at line 85 of file itkThreadPool.h.
|
private |
Definition at line 161 of file itkThreadPool.h.
|
private |
To lock on the vectors
Definition at line 226 of file itkThreadPool.h.
|
private |
To lock on the vectors
Definition at line 230 of file itkThreadPool.h.
typedef int itk::ThreadPool::ThreadTimeType |
local class typedefs.
Definition at line 83 of file itkThreadPool.h.
|
private |
Vector of pairs that hold job ids and their corresponding thread handles
Enumerator | |
---|---|
JOB_THREADHANDLE_JUST_ADDED | |
JOB_THREADHANDLE_IS_FREE | |
JOB_THREADHANDLE_IS_DONE |
Definition at line 178 of file itkThreadPool.h.
|
protected |
|
protectedvirtual |
|
private |
|
private |
Called to add a thread to the thread pool. This method add a thread to the thread pool and pushes the thread handle into the m_ThreadHandles set
ThreadProcessIdType itk::ThreadPool::AssignWork | ( | ThreadJob | worker | ) |
This method is called to assign a job to the thread pool
|
staticprivate |
Method to compare thread handles - true for same false for different
|
private |
To lock on the vectors
|
private |
This function is called by the threads to get jobs to be executed. This method is the "first" call from the threads in the thread pool. Now this method blocks the thread until a job is available for the thread to execute. Once a job is available(known from m_ThreadProcessIdentifiersVector), it gets it from the worker queue and returns it
|
private |
To check if the thread pool has to add a thread. This method checks if any threads in the thread pool are free. If so, it returns false else returns true
|
static |
Returns the global singleton instance of the ThreadPool
This method is a Singleton and does not have a New method.
|
virtual |
Run-time type information (and related methods).
Reimplemented from itk::Object.
|
private |
To lock on the vectors
|
private |
To lock on the vectors
|
private |
To lock on the vectors
|
private |
Used under windows - gets the thread handle associated with thread id
void itk::ThreadPool::InitializeThreads | ( | ThreadCountType | maxThreads | ) |
Can call this method if we want to pre-start maxThreads in the thread pool
|
static |
Returns the global instance of the ThreadPool
|
private |
|
private |
Used to remove an active job id from the queue because it is done. This method is called by the threads once they are done with the job. This method removes the job id from m_ActiveJobIds, marks the thread as free by setting appropriate values in the m_ThreadProcessIdentifiersVector vector and removes the job from m_WorkerQueue
|
staticprivate |
thread function
bool itk::ThreadPool::WaitForJobOnThreadHandle | ( | ThreadProcessIdType | handle | ) |
This method blocks until the given (job) id has finished executing
|
private |
set if exception occurs
Definition at line 153 of file itkThreadPool.h.
|
private |
counter to assign job ids
Definition at line 150 of file itkThreadPool.h.
|
staticprivate |
To lock on m_NumberOfPendingJobsToBeRun
Definition at line 147 of file itkThreadPool.h.
|
private |
Set when the thread pool is to be stopped
Definition at line 141 of file itkThreadPool.h.
|
private |
Maintains count of threads
Definition at line 144 of file itkThreadPool.h.
|
private |
Vector to hold all active thread handles
Definition at line 174 of file itkThreadPool.h.
|
staticprivate |
To lock on the vectors
Definition at line 262 of file itkThreadPool.h.
|
staticprivate |
To lock on m_ThreadPoolInstance
Definition at line 264 of file itkThreadPool.h.
|
private |
To lock on the vectors
Definition at line 227 of file itkThreadPool.h.
|
staticprivate |
To lock on the vectors
Definition at line 236 of file itkThreadPool.h.
|
private |
To lock on the vectors
Definition at line 233 of file itkThreadPool.h.
|
private |
To lock on the vectors
Definition at line 232 of file itkThreadPool.h.
|
private |
this is a list of jobs(ThreadJob) submitted to the thread pool this is the only place where the jobs are submitted. We need a worker queue because the thread pool assigns work to a thread which is free. So when a job is submitted, it has to be stored somewhere
Definition at line 168 of file itkThreadPool.h.
|
staticprivate |
To lock on m_WorkerQueue
Definition at line 171 of file itkThreadPool.h.