Open CASCADE Technology  7.5.0
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions

OSD_ThreadPool Class Reference

Class defining a thread pool for executing algorithms in multi-threaded mode. Thread pool allocates requested amount of threads and keep them alive (in sleep mode when unused) during thread pool lifetime. The same pool can be used by multiple consumers, including nested multi-threading algorithms and concurrent threads: More...

#include <OSD_ThreadPool.hxx>

Inheritance diagram for OSD_ThreadPool:
Inheritance graph
[legend]

Data Structures

class  EnumeratedThread
 Thread with back reference to thread pool and thread index in it. More...
 
class  Job
 Auxiliary wrapper class for thread function. More...
 
class  JobInterface
 Thread function interface. More...
 
class  JobRange
 Auxiliary class which ensures exclusive access to iterators of processed data pool. More...
 
class  Launcher
 Launcher object locking a subset of threads (or all threads) in a thread pool to perform parallel execution of the job. More...
 

Public Member Functions

 OSD_ThreadPool (int theNbThreads=-1)
 Main constructor. Application may consider specifying more threads than actually available (OSD_Parallel::NbLogicalProcessors()) and set up NbDefaultThreadsToLaunch() to a smaller value so that concurrent threads will be able using single Thread Pool instance more efficiently. More...
 
virtual ~OSD_ThreadPool ()
 Destructor. More...
 
bool HasThreads () const
 Return TRUE if at least 2 threads are available (including self-thread). More...
 
int LowerThreadIndex () const
 Return the lower thread index. More...
 
int UpperThreadIndex () const
 Return the upper thread index (last index is reserved for self-thread). More...
 
int NbThreads () const
 Return the number of threads; >= 1. More...
 
int NbDefaultThreadsToLaunch () const
 Return maximum number of threads to be locked by a single Launcher object by default; the entire thread pool size is returned by default. More...
 
void SetNbDefaultThreadsToLaunch (int theNbThreads)
 Set maximum number of threads to be locked by a single Launcher object by default. Should be set BEFORE first usage. More...
 
bool IsInUse ()
 Checks if thread pools has active consumers. More...
 
void Init (int theNbThreads)
 Reinitialize the thread pool with a different number of threads. Should be called only with no active jobs, or exception Standard_ProgramError will be thrown! More...
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor. More...
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing. More...
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter. More...
 
virtual ~Standard_Transient ()
 Destructor must be virtual. More...
 
virtual void Delete () const
 Memory deallocator for transient classes. More...
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object. More...
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type. More...
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName. More...
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism. More...
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero. More...
 
Standard_Integer GetRefCount () const
 Get the reference counter of this object. More...
 
void IncrementRefCounter () const
 Increments the reference counter of this object. More...
 
Standard_Integer DecrementRefCounter () const
 Decrements the reference counter of this object; returns the decremented value. More...
 

Static Public Member Functions

static const Handle< OSD_ThreadPool > & DefaultPool (int theNbThreads=-1)
 Return (or create) a default thread pool. Number of threads argument will be considered only when called first time. More...
 
- Static Public Member Functions inherited from Standard_Transient
static const char * get_type_name ()
 Returns a type descriptor about this object. More...
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class. More...
 

Protected Member Functions

void release ()
 Release threads. More...
 

Static Protected Member Functions

static void performJob (Handle< Standard_Failure > &theFailure, OSD_ThreadPool::JobInterface *theJob, int theThreadIndex)
 Perform the job and catch exceptions. More...
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object. More...
 

Detailed Description

Class defining a thread pool for executing algorithms in multi-threaded mode. Thread pool allocates requested amount of threads and keep them alive (in sleep mode when unused) during thread pool lifetime. The same pool can be used by multiple consumers, including nested multi-threading algorithms and concurrent threads:

Constructor & Destructor Documentation

◆ OSD_ThreadPool()

OSD_ThreadPool::OSD_ThreadPool ( int  theNbThreads = -1)

Main constructor. Application may consider specifying more threads than actually available (OSD_Parallel::NbLogicalProcessors()) and set up NbDefaultThreadsToLaunch() to a smaller value so that concurrent threads will be able using single Thread Pool instance more efficiently.

Parameters
theNbThreadsthreads number to be created by pool (if -1 is specified then OSD_Parallel::NbLogicalProcessors() will be used)

◆ ~OSD_ThreadPool()

virtual OSD_ThreadPool::~OSD_ThreadPool ( )
virtual

Destructor.

Member Function Documentation

◆ DefaultPool()

static const Handle< OSD_ThreadPool >& OSD_ThreadPool::DefaultPool ( int  theNbThreads = -1)
static

Return (or create) a default thread pool. Number of threads argument will be considered only when called first time.

◆ HasThreads()

bool OSD_ThreadPool::HasThreads ( ) const
inline

Return TRUE if at least 2 threads are available (including self-thread).

◆ Init()

void OSD_ThreadPool::Init ( int  theNbThreads)

Reinitialize the thread pool with a different number of threads. Should be called only with no active jobs, or exception Standard_ProgramError will be thrown!

◆ IsInUse()

bool OSD_ThreadPool::IsInUse ( )

Checks if thread pools has active consumers.

◆ LowerThreadIndex()

int OSD_ThreadPool::LowerThreadIndex ( ) const
inline

Return the lower thread index.

◆ NbDefaultThreadsToLaunch()

int OSD_ThreadPool::NbDefaultThreadsToLaunch ( ) const
inline

Return maximum number of threads to be locked by a single Launcher object by default; the entire thread pool size is returned by default.

◆ NbThreads()

int OSD_ThreadPool::NbThreads ( ) const
inline

Return the number of threads; >= 1.

◆ performJob()

static void OSD_ThreadPool::performJob ( Handle< Standard_Failure > &  theFailure,
OSD_ThreadPool::JobInterface theJob,
int  theThreadIndex 
)
staticprotected

Perform the job and catch exceptions.

◆ release()

void OSD_ThreadPool::release ( )
protected

Release threads.

◆ SetNbDefaultThreadsToLaunch()

void OSD_ThreadPool::SetNbDefaultThreadsToLaunch ( int  theNbThreads)
inline

Set maximum number of threads to be locked by a single Launcher object by default. Should be set BEFORE first usage.

◆ UpperThreadIndex()

int OSD_ThreadPool::UpperThreadIndex ( ) const
inline

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


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