This class manages multiple threads and fills them with work.
More...
#include <ThreadPool.hpp>
|
| ThreadPool (size_t numThreads) |
| Constructor. Launches some amount of workers. More...
|
|
| ~ThreadPool () |
| Destructor. This joins all threads. More...
|
|
template<class Function , class... Args> |
std::future< typename
std::result_of< Function(Args...)>
::type > | enqueue (Function &&function, Args &&...args) |
| Enqueue work for the thread pool. More...
|
|
void | stop () |
| Stop the thread pool. This method is non-blocking. More...
|
|
void | waitForEmptyQueue () const |
| This method blocks until the queue is empty. More...
|
|
This class manages multiple threads and fills them with work.
okvis::ThreadPool::ThreadPool |
( |
size_t |
numThreads | ) |
|
Constructor. Launches some amount of workers.
- Parameters
-
[in] | numThreads | The number of threads in the pool. |
okvis::ThreadPool::~ThreadPool |
( |
| ) |
|
Destructor. This joins all threads.
template<class Function , class... Args>
std::future< typename std::result_of< Function(Args...)>::type > okvis::ThreadPool::enqueue |
( |
Function && |
function, |
|
|
Args &&... |
args |
|
) |
| |
Enqueue work for the thread pool.
Pass in a function and its arguments to enqueue work in the thread pool
- Parameters
-
[in] | function | A function pointer to be called by a thread. |
| args | Function arguments. |
- Returns
- A std::future that will return the result of calling function. If this function is called after the thread pool has been stopped, it will return an uninitialized future that will return future.valid() == false
void okvis::ThreadPool::run |
( |
| ) |
|
|
private |
void okvis::ThreadPool::stop |
( |
| ) |
|
|
inline |
Stop the thread pool. This method is non-blocking.
void okvis::ThreadPool::waitForEmptyQueue |
( |
| ) |
const |
This method blocks until the queue is empty.
unsigned okvis::ThreadPool::active_threads_ |
|
private |
A counter of active threads.
volatile bool okvis::ThreadPool::stop_ |
|
private |
A signal to stop the threads.
std::queue<std::function<void()> > okvis::ThreadPool::tasks_ |
|
private |
std::condition_variable okvis::ThreadPool::tasks_condition_ |
|
mutableprivate |
A condition variable for worker threads.
std::mutex okvis::ThreadPool::tasks_mutex_ |
|
mutableprivate |
A mutex to protect the list of tasks.
std::condition_variable okvis::ThreadPool::wait_condition_ |
|
mutableprivate |
std::vector<std::thread> okvis::ThreadPool::workers_ |
|
private |
Need to keep track of threads so we can join them.
The documentation for this class was generated from the following files: