Open CASCADE Technology
7.7.0
|
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>
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_Transient & | operator= (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_Transient * | This () 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... | |
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:
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.
theNbThreads | threads number to be created by pool (if -1 is specified then OSD_Parallel::NbLogicalProcessors() will be used) |
|
virtual |
Destructor.
|
static |
Return (or create) a default thread pool. Number of threads argument will be considered only when called first time.
|
inline |
Return TRUE if at least 2 threads are available (including self-thread).
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!
bool OSD_ThreadPool::IsInUse | ( | ) |
Checks if thread pools has active consumers.
|
inline |
Return the lower thread index.
|
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.
|
inline |
Return the number of threads; >= 1.
|
staticprotected |
Perform the job and catch exceptions.
|
protected |
Release threads.
|
inline |
Set maximum number of threads to be locked by a single Launcher object by default. Should be set BEFORE first usage.
|
inline |
Return the upper thread index (last index is reserved for self-thread).