[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

ThreadPool Class Reference

Thread pool class to manage a set of parallel workers. More...

#include <vigra/threadpool.hxx>

Public Member Functions

template<class F>
threading::future< void > enqueue (F &&f)
 
template<class F>
auto enqueueReturning (F &&f) -> threading::future< decltype(f(0))>
 
size_t nThreads () const
 
 ThreadPool (const int n)
 
 ThreadPool (const ParallelOptions &options)
 
void waitFinished ()
 
 ~ThreadPool ()
 

Detailed Description

Thread pool class to manage a set of parallel workers.

#include <vigra/threadpool.hxx>
Namespace: vigra

Constructor & Destructor Documentation

◆ ThreadPool() [1/2]

ThreadPool ( const ParallelOptions & options)

Create a thread pool from ParallelOptions. The constructor just launches the desired number of workers. If the number of threads is zero, no workers are started, and all tasks will be executed in synchronously in the present thread.

◆ ThreadPool() [2/2]

ThreadPool ( const int n)

Create a thread pool with n threads. The constructor just launches the desired number of workers. If

  • n is ParallelOptions::Auto, the number of threads is determined by threading::thread::hardware_concurrency(). ParallelOptions::Nice will create half as many threads. If n = 0, no workers are started, and all tasks will be executed synchronously in the present thread. If the preprocessor flag VIGRA_SINGLE_THREADED is defined, the number of threads is always set to zero (i.e. synchronous execution), regardless of the value of
  • n. This is useful for debugging.

◆ ~ThreadPool()

~ThreadPool ( )

The destructor joins all threads.

Member Function Documentation

◆ enqueueReturning()

template<class F>
auto enqueueReturning ( F && f) -> threading::future<decltype(f(0))>

Enqueue a task that will be executed by the thread pool. The task result can be obtained using the get() function of the returned future. If the task throws an exception, it will be raised on the call to get().

◆ enqueue()

template<class F>
threading::future< void > enqueue ( F && f)

Enqueue function for tasks without return value. This is a special case of the enqueueReturning template function, but some compilers fail on std::result_of<F(int)>::type for void(int) functions.

◆ waitFinished()

void waitFinished ( )

Block until all tasks are finished.

◆ nThreads()

size_t nThreads ( ) const

Return the number of worker threads.


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

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.12.2 (Mon Apr 14 2025)