![]() |
ITK
4.13.0
Insight Segmentation and Registration Toolkit
|
#include <itkThreadPool.h>
Thread pool maintains a constant number of threads.
Thread pool is called and initialized from within the MultiThreader. Initially the thread pool is started with GlobalDefaultNumberOfThreads. 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 ThreadPool by calling its AddWork method. One can then wait for the job by calling the WaitForJob method.
When thread pool is in use by the MultiThreader, invoking SetNumberOfThreads on MultiThreader will only increase the number of jobs submitted to the ThreadPool, it will not increase the number of threads. This trick can be used to increase the number of chunks, which can help load balancing in case the algorithm takes more time for some parts of the image, and there is relatively small overhead for chunking (splitting the image for processing).
If more threads are required, e.g. in case when Barrier is used, AddThreads method should be invoked.
Definition at line 61 of file itkThreadPool.h.
Public Types | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef ThreadPool | Self |
typedef ThreadJob::Semaphore | Semaphore |
typedef Object | Superclass |
![]() | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef Object | Self |
typedef LightObject | Superclass |
![]() | |
typedef SmartPointer< const Self > | ConstPointer |
typedef SmartPointer< Self > | Pointer |
typedef LightObject | Self |
Public Member Functions | |
void | AddThreads (ThreadIdType count) |
void | AddWork (const ThreadJob &job) |
virtual const char * | GetNameOfClass () const |
int | GetNumberOfCurrentlyIdleThreads () const |
void | WaitForJob (Semaphore &jobSemaphore) |
![]() | |
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 |
![]() | |
virtual void | Delete () |
virtual int | GetReferenceCount () const |
itkCloneMacro (Self) | |
void | Print (std::ostream &os, Indent indent=0) const |
Static Public Member Functions | |
static ThreadIdType | GetGlobalDefaultNumberOfThreads () |
static ThreadIdType | GetGlobalDefaultNumberOfThreadsByPlatform () |
static Pointer | GetInstance () |
static Pointer | New () |
![]() | |
static bool | GetGlobalWarningDisplay () |
static void | GlobalWarningDisplayOff () |
static void | GlobalWarningDisplayOn () |
static Pointer | New () |
static void | SetGlobalWarningDisplay (bool flag) |
![]() | |
static void | BreakOnError () |
static Pointer | New () |
Protected Member Functions | |
void | AddThread () |
void | DeleteThreads () |
ThreadPool () | |
virtual | ~ThreadPool () override |
![]() | |
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 () override |
![]() | |
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 () |
Static Protected Member Functions | |
static bool | PlatformClose (ThreadProcessIdType &threadId) |
static void | PlatformCreate (Semaphore &semaphore) |
static void | PlatformDelete (Semaphore &semaphore) |
static void | PlatformSignal (Semaphore &semaphore) |
static void | PlatformWait (Semaphore &semaphore) |
Static Private Member Functions | |
static ITK_THREAD_RETURN_TYPE | ThreadExecute (void *param) |
Private Attributes | |
bool | m_ExceptionOccurred |
std::vector< ThreadProcessIdType > | m_Threads |
Semaphore | m_ThreadsSemaphore |
std::deque< ThreadJob > | m_WorkQueue |
Static Private Attributes | |
static SimpleFastMutexLock | m_Mutex |
static Pointer | m_ThreadPoolInstance |
Additional Inherited Members | |
![]() | |
AtomicInt< int > | m_ReferenceCount |
typedef SmartPointer<const Self> itk::ThreadPool::ConstPointer |
Definition at line 69 of file itkThreadPool.h.
typedef SmartPointer< Self > itk::ThreadPool::Pointer |
Definition at line 68 of file itkThreadPool.h.
typedef ThreadPool itk::ThreadPool::Self |
Standard class typedefs.
Definition at line 66 of file itkThreadPool.h.
typedef ThreadJob::Semaphore itk::ThreadPool::Semaphore |
Definition at line 71 of file itkThreadPool.h.
typedef Object itk::ThreadPool::Superclass |
Definition at line 67 of file itkThreadPool.h.
|
protected |
|
overrideprotectedvirtual |
|
protected |
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_Threads vector.
void itk::ThreadPool::AddThreads | ( | ThreadIdType | count | ) |
Can call this method if we want to add extra threads to the pool.
void itk::ThreadPool::AddWork | ( | const ThreadJob & | job | ) |
Add this job to the thread pool queue. All data members of the ThreadJob must be filled. The semaphore pointer must point to a valid semaphore structure. AddWork will initialize that semaphore, and the invoker must pass it to WaitForJob in order to wait for the job's completion.
|
protected |
Platform-specific function to clean up all the threads.
|
static |
Examines environment variables and falls back to hyper-threaded core count
|
static |
Platform specific number of threads
|
static |
Returns the global singleton instance of the ThreadPool
|
virtual |
Run-time type information (and related methods).
Reimplemented from itk::Object.
int itk::ThreadPool::GetNumberOfCurrentlyIdleThreads | ( | ) | const |
The approximate number of idle threads.
|
static |
Returns the global instance
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprivate |
The continuously running thread function
void itk::ThreadPool::WaitForJob | ( | Semaphore & | jobSemaphore | ) |
This method blocks until the given job has finished executing.
|
private |
Set if exception occurs
Definition at line 126 of file itkThreadPool.h.
|
staticprivate |
To lock on the internal variables
Definition at line 148 of file itkThreadPool.h.
|
staticprivate |
Definition at line 150 of file itkThreadPool.h.
|
private |
Vector to hold all thread handles. Thread handles are used to delete the threads.
Definition at line 145 of file itkThreadPool.h.
|
private |
When a thread is idle, it is waiting on m_ThreadsSemaphore. AddWork signals this semaphore to resume a (random) thread.
Definition at line 140 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. Filled by AddWork, emptied by ThreadExecute.
Definition at line 135 of file itkThreadPool.h.