|
Glib::ThreadPool Class ReferenceA pool of threads to execute work concurrently.
More...
|
Public Methods | |
ThreadPool (int max_threads=-1, bool exclusive=false) | |
Constructs a new thread pool. | |
virtual | ~ThreadPool () |
void | push (const SigC::Slot0<void>& slot) |
Inserts slot into the list of tasks to be executed by the pool. | |
void | set_max_threads (int max_threads) |
Sets the maximal allowed number of threads for the pool. | |
int | get_max_threads () const |
Returns the maximal number of threads for the pool. | |
unsigned int | get_num_threads () const |
Returns the number of threads currently running in the pool. | |
unsigned int | unprocessed () const |
Returns the number of tasks still unprocessed in the pool. | |
bool | get_exclusive () const |
Returns whether all threads are exclusive to this pool. | |
void | shutdown (bool immediately=false) |
Frees all resources allocated for the pool. | |
GThreadPool* | gobj () |
const GThreadPool* | gobj () const |
Static Public Methods | |
void | set_max_unused_threads (int max_threads) |
Sets the maximal number of unused threads to max_threads. | |
int | get_max_unused_threads () |
Returns the maximal allowed number of unused threads. | |
unsigned int | get_num_unused_threads () |
Returns the number of currently unused threads. | |
void | stop_unused_threads () |
Stops all currently unused threads. |
|
Constructs a new thread pool. Whenever you call ThreadPool::push(), either a new thread is created or an unused one is reused. At most max_threads threads are running concurrently for this thread pool. max_threads = -1 allows unlimited threads to be created for this thread pool.
The parameter exclusive determines, whether the thread pool owns all threads exclusive or whether the threads are shared globally. If exclusive is
|
|
|
|
Returns whether all threads are exclusive to this pool.
|
|
Returns the maximal number of threads for the pool.
|
|
Returns the maximal allowed number of unused threads.
|
|
Returns the number of threads currently running in the pool.
|
|
Returns the number of currently unused threads.
|
|
|
|
|
|
Inserts slot into the list of tasks to be executed by the pool. When the number of currently running threads is lower than the maximal allowed number of threads, a new thread is started (or reused). Otherwise slot stays in the queue until a thread in this pool finishes its previous task and processes slot.
|
|
Sets the maximal allowed number of threads for the pool. A value of -1 means that the maximal number of threads is unlimited. Setting max_threads to 0 means stopping all work for pool. It is effectively frozen until max_threads is set to a non-zero value again. A thread is never terminated while it is still running. Instead the maximal number of threads only has effect for the allocation of new threads in ThreadPool::push(). A new thread is allocated whenever the number of currently running threads in the pool is smaller than the maximal number.
|
|
Sets the maximal number of unused threads to max_threads. If max_threads is -1, no limit is imposed on the number of unused threads.
|
|
Frees all resources allocated for the pool.
If immediately is This method does not return before all tasks to be processed (dependent on immediately, whether all or only the currently running) are ready. After calling shutdown() the pool must not be used anymore.
|
|
Stops all currently unused threads. This does not change the maximal number of unused threads. This function can be used to regularly stop all unused threads e.g. from Glib::signal_timeout(). |
|
Returns the number of tasks still unprocessed in the pool.
|