Represents a collection of a fixed number of threads, which tasks can be added to.
More...
#include <thread_pool.h>
|
| thread_pool (size_t num_threads=std::thread::hardware_concurrency()) |
|
| ~thread_pool () |
| Destructor; joins all threads.
|
|
template<class Function > |
std::future< typename std::result_of< Function()>::type > | submit_task (Function func) |
| Adds a task to the thread_pool. More...
|
|
std::vector< std::thread::id > | thread_ids () const |
|
size_t | tasks () const |
|
|
void | worker () |
| Function invoked by the worker threads to process tasks off the internal queue.
|
|
|
std::vector< std::thread > | threads_ |
| the threads in the pool
|
|
std::queue< std::unique_ptr< task > > | tasks_ |
| the queue containing the tasks to be run
|
|
bool | running_ |
| whether or not the pool is currently running
|
|
std::mutex | mutex_ |
| the mutex to wrap queue operations
|
|
std::condition_variable | cond_ |
| the condition variable that workers sleep on when waiting for work
|
|
Represents a collection of a fixed number of threads, which tasks can be added to.
meta::parallel::thread_pool::thread_pool |
( |
size_t |
num_threads = std::thread::hardware_concurrency() | ) |
|
|
inline |
- Parameters
-
num_threads | The number of threads to initialize this thread_pool with; by default, the hardware concurrency. |
template<class Function >
std::future<typename std::result_of<Function()>::type> meta::parallel::thread_pool::submit_task |
( |
Function |
func | ) |
|
|
inline |
Adds a task to the thread_pool.
- Parameters
-
func | The function (task) to add |
- Returns
- a std::future that wraps the return value of the task for retrieval later
std::vector<std::thread::id> meta::parallel::thread_pool::thread_ids |
( |
| ) |
const |
|
inline |
- Returns
- a vector of the thread_ids from the current pool
size_t meta::parallel::thread_pool::tasks |
( |
| ) |
const |
|
inline |
- Returns
- the number of currently queued tasks
The documentation for this class was generated from the following file: