manages a fixed number of worker threads that execute queued tasks.
More...
#include <thread-pool.hpp>
|
| void | worker () |
| | threads execute tasks from the queue.
|
| |
|
| std::mutex | mtx |
| | mutex for concurrent access to tasks.
|
| |
| std::condition_variable | cv |
| | condition variable for waiting/notifying.
|
| |
| bool | stop |
| | flag that handles stoppage of worker threads.
|
| |
| queue< std::function< void()> > | tasks |
| | queue of tasks.
|
| |
| std::thread * | threads |
| | list of threads owned by thread pool.
|
| |
| size_t | thread_count |
| | number of threads in a thread pool.
|
| |
manages a fixed number of worker threads that execute queued tasks.
◆ thread_pool()
| thread_pool::thread_pool |
( |
size_t |
thread_count | ) |
|
starts specified number of worker threads.
- Parameters
-
| thread_count | - number of worker threads that handle tasks. |
◆ ~thread_pool()
| thread_pool::~thread_pool |
( |
| ) |
|
stopping all worker threads.
◆ enqueue()
template<typename T >
| void thread_pool::enqueue |
( |
T && |
f | ) |
|
|
inline |
adding new task to the queue
- Parameters
-
| f | - task that is being added to queue. |
- Exceptions
-
| std::runtime_error | - when called after all worker threads stopped working. |
◆ worker()
| void thread_pool::worker |
( |
| ) |
|
|
private |
threads execute tasks from the queue.
◆ cv
| std::condition_variable thread_pool::cv |
|
private |
condition variable for waiting/notifying.
◆ mtx
| std::mutex thread_pool::mtx |
|
private |
mutex for concurrent access to tasks.
◆ stop
flag that handles stoppage of worker threads.
◆ tasks
| queue<std::function<void()> > thread_pool::tasks |
|
private |
◆ thread_count
| size_t thread_pool::thread_count |
|
private |
number of threads in a thread pool.
◆ threads
| std::thread* thread_pool::threads |
|
private |
list of threads owned by thread pool.
The documentation for this class was generated from the following files: