#include <threadpool.hpp>
◆ ThreadPool() [1/3]
| ThreadPool::ThreadPool |
( |
size_t |
thread_count = std::thread::hardware_concurrency() | ) |
|
Construct a new ThreadPool object.
This constructor initializes the thread pool with a specified number of worker threads. The threads will be created and will start running immediately, waiting for tasks to be enqueued. The thread pool will manage the execution of tasks concurrently across the worker threads, allowing for efficient parallel processing of tasks.
- Parameters
-
| thread_count | The number of worker threads to create in the thread pool. By default, this is set to the number of hardware threads available on the system, allowing for efficient parallel execution of tasks |
◆ ~ThreadPool()
| ThreadPool::~ThreadPool |
( |
| ) |
|
Destroy the ThreadPool object.
This destructor is responsible for shutting down the thread pool and ensuring that all worker threads are properly joined before the ThreadPool object is destroyed. It will signal the worker threads to stop and then wait for them to finish executing any remaining tasks before cleaning up resources
◆ ThreadPool() [2/3]
◆ ThreadPool() [3/3]
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ schedule()
| void ThreadPool::schedule |
( |
std::function< void()> |
task | ) |
|
|
overridevirtual |
Enqueues a new task to be executed by the thread pool.
This method allows you to add a new task to the thread pool's queue of tasks to be executed. The provided task will be added to the queue, and one of the worker threads will pick it up and execute it as soon as it is available. The task can be any callable object, such as a lambda, function pointer, or std::function
- Parameters
-
| task | The task to be executed by the thread pool. This can be any callable object, such as a lambda, function pointer, or std::function |
Implements IScheduler.
◆ shutdown()
| void ThreadPool::shutdown |
( |
| ) |
|
|
overridevirtual |
Shuts down the thread pool and stops all worker threads.
This method signals the worker threads to stop processing tasks and then waits for them to finish executing any remaining tasks before shutting down. After calling this method, the thread pool will no longer accept new tasks, and all worker threads will be joined before the method returns
Implements IScheduler.
◆ wait()
| void ThreadPool::wait |
( |
| ) |
|
|
overridevirtual |
Waits for all currently enqueued tasks to be completed.
This method blocks until all tasks that have been enqueued in the thread pool have been completed. It will wait for all worker threads to finish executing their current tasks and ensure that the task queue is empty before returning. This can be useful for synchronizing with the completion of tasks before proceeding with further operations
Implements IScheduler.
The documentation for this class was generated from the following file: