Open CASCADE Technology 7.8.2.dev
|
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. | |
virtual | ~OSD_ThreadPool () |
Destructor. | |
bool | HasThreads () const |
Return TRUE if at least 2 threads are available (including self-thread). | |
int | LowerThreadIndex () const |
Return the lower thread index. | |
int | UpperThreadIndex () const |
Return the upper thread index (last index is reserved for self-thread). | |
int | NbThreads () const |
Return the number of threads; >= 1. | |
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. | |
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. | |
bool | IsInUse () |
Checks if thread pools has active consumers. | |
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! | |
Public Member Functions inherited from Standard_Transient | |
Standard_Transient () | |
Empty constructor. | |
Standard_Transient (const Standard_Transient &) | |
Copy constructor – does nothing. | |
Standard_Transient & | operator= (const Standard_Transient &) |
Assignment operator, needed to avoid copying reference counter. | |
virtual | ~Standard_Transient () |
Destructor must be virtual. | |
virtual const opencascade::handle< Standard_Type > & | DynamicType () const |
Returns a type descriptor about this object. | |
Standard_Boolean | IsInstance (const opencascade::handle< Standard_Type > &theType) const |
Returns a true value if this is an instance of Type. | |
Standard_Boolean | IsInstance (const Standard_CString theTypeName) const |
Returns a true value if this is an instance of TypeName. | |
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. | |
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. | |
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. | |
Standard_Integer | GetRefCount () const noexcept |
Get the reference counter of this object. | |
void | IncrementRefCounter () noexcept |
Increments the reference counter of this object. | |
Standard_Integer | DecrementRefCounter () noexcept |
Decrements the reference counter of this object; returns the decremented value. | |
virtual void | Delete () const |
Memory deallocator for transient classes. | |
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. | |
Static Public Member Functions inherited from Standard_Transient | |
static constexpr const char * | get_type_name () |
Returns a type descriptor about this object. | |
static const opencascade::handle< Standard_Type > & | get_type_descriptor () |
Returns type descriptor of Standard_Transient class. | |
Protected Member Functions | |
void | release () |
Release threads. | |
Static Protected Member Functions | |
static void | performJob (Handle< Standard_Failure > &theFailure, OSD_ThreadPool::JobInterface *theJob, int theThreadIndex) |
Perform the job and catch exceptions. | |
Additional Inherited Members | |
Public Types inherited from Standard_Transient | |
typedef void | base_type |
Returns a type descriptor about this object. | |
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).