Open CASCADE Technology  7.5.0
Public Member Functions | Protected Member Functions

OSD_ThreadPool::Launcher Class Reference

Launcher object locking a subset of threads (or all threads) in a thread pool to perform parallel execution of the job. More...

#include <OSD_ThreadPool.hxx>

Public Member Functions

 Launcher (OSD_ThreadPool &thePool, int theMaxThreads=-1)
 Lock specified number of threads from the thread pool. If thread pool is already locked by another user, Launcher will lock as many threads as possible (if none will be locked, then single threaded execution will be done). More...
 
 ~Launcher ()
 Release threads. More...
 
bool HasThreads () const
 Return TRUE if at least 2 threads have been locked for parallel execution (including self-thread); otherwise, the functor will be executed within the caller thread. More...
 
int NbThreads () const
 Return amount of locked threads; >= 1. More...
 
int LowerThreadIndex () const
 Return the lower thread index. More...
 
int UpperThreadIndex () const
 Return the upper thread index (last index is reserved for the self-thread). More...
 
template<typename Functor >
void Perform (int theBegin, int theEnd, const Functor &theFunctor)
 Simple primitive for parallelization of "for" loops, e.g.: More...
 
void Release ()
 Release threads before Launcher destruction. More...
 

Protected Member Functions

void perform (JobInterface &theJob)
 Execute job. More...
 
void run (JobInterface &theJob)
 Initialize job and start threads. More...
 
void wait ()
 Wait threads execution. More...
 

Detailed Description

Launcher object locking a subset of threads (or all threads) in a thread pool to perform parallel execution of the job.

Constructor & Destructor Documentation

◆ Launcher()

OSD_ThreadPool::Launcher::Launcher ( OSD_ThreadPool thePool,
int  theMaxThreads = -1 
)

Lock specified number of threads from the thread pool. If thread pool is already locked by another user, Launcher will lock as many threads as possible (if none will be locked, then single threaded execution will be done).

Parameters
thePoolthread pool to lock the threads
theMaxThreadsnumber of threads to lock; -1 specifies that default number of threads to be used OSD_ThreadPool::NbDefaultThreadsToLaunch()

◆ ~Launcher()

OSD_ThreadPool::Launcher::~Launcher ( )
inline

Release threads.

Member Function Documentation

◆ HasThreads()

bool OSD_ThreadPool::Launcher::HasThreads ( ) const
inline

Return TRUE if at least 2 threads have been locked for parallel execution (including self-thread); otherwise, the functor will be executed within the caller thread.

◆ LowerThreadIndex()

int OSD_ThreadPool::Launcher::LowerThreadIndex ( ) const
inline

Return the lower thread index.

◆ NbThreads()

int OSD_ThreadPool::Launcher::NbThreads ( ) const
inline

Return amount of locked threads; >= 1.

◆ Perform()

template<typename Functor >
void OSD_ThreadPool::Launcher::Perform ( int  theBegin,
int  theEnd,
const Functor &  theFunctor 
)
inline

Simple primitive for parallelization of "for" loops, e.g.:

for (int anIter = theBegin; anIter < theEnd; ++anIter) {}
Parameters
theBeginthe first data index (inclusive)
theEndthe last data index (exclusive)
theFunctorfunctor providing an interface "void operator(int theThreadIndex, int theDataIndex){}" performing task for specified index

◆ perform()

void OSD_ThreadPool::Launcher::perform ( JobInterface theJob)
protected

Execute job.

◆ Release()

void OSD_ThreadPool::Launcher::Release ( )

Release threads before Launcher destruction.

◆ run()

void OSD_ThreadPool::Launcher::run ( JobInterface theJob)
protected

Initialize job and start threads.

◆ UpperThreadIndex()

int OSD_ThreadPool::Launcher::UpperThreadIndex ( ) const
inline

Return the upper thread index (last index is reserved for the self-thread).

◆ wait()

void OSD_ThreadPool::Launcher::wait ( )
protected

Wait threads execution.


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