Thread pool class.
More...
#include <ThreadPool.h>
|
| ThreadPool (std::string thread_pool_name=THREAD_DEFAULT_NAME, size_t threads=4) |
| Initialize the thread pool.
|
|
| ~ThreadPool () override |
|
void | postTask (const std::function< void()> &task) |
| Add a single task to the thread pool.
|
|
void | postTask (const std::vector< std::function< void()> > &tasks) |
| Add multiple tasks to the thread pool.
|
|
template<typename FUNCTION , typename... ARGS> |
void | postTaskEx (FUNCTION &&f, ARGS &&...args) |
| Add a task to the thread pool and bind parameters.
|
|
template<class RETURN_TYPE > |
std::shared_future< RETURN_TYPE > | postTask (const std::function< RETURN_TYPE()> &tasks) |
| Add a task with a return value to the thread pool.
|
|
void | shutdown () |
| Shutdown the current thread pool and block until all child threads exit.
|
|
size_t | size () noexcept |
|
bool | empty () noexcept |
|
const std::string & | getName () const |
|
size_t | getThreads () const |
|
| Noncopyable ()=default |
|
virtual | ~Noncopyable ()=default |
|
| Noncopyable (const Noncopyable &)=delete |
|
Noncopyable & | operator= (const Noncopyable &)=delete |
|
◆ Ptr
◆ ThreadPool()
sese::ThreadPool::ThreadPool |
( |
std::string | thread_pool_name = THREAD_DEFAULT_NAME, |
|
|
size_t | threads = 4 ) |
|
explicit |
Initialize the thread pool.
- Parameters
-
thread_pool_name | Name of the thread pool (affects the names of the threads in the pool) |
threads | Number of threads |
References data, name, threadGroup, and threads.
◆ ~ThreadPool()
sese::ThreadPool::~ThreadPool |
( |
| ) |
|
|
override |
◆ empty()
bool sese::ThreadPool::empty |
( |
| ) |
|
|
nodiscardnoexcept |
◆ getName()
const std::string & sese::ThreadPool::getName |
( |
| ) |
const |
|
inlinenodiscard |
◆ getThreads()
size_t sese::ThreadPool::getThreads |
( |
| ) |
const |
|
inlinenodiscard |
◆ postTask() [1/3]
template<class RETURN_TYPE >
std::shared_future< RETURN_TYPE > sese::ThreadPool::postTask |
( |
const std::function< RETURN_TYPE()> & | tasks | ) |
|
Add a task with a return value to the thread pool.
- Template Parameters
-
- Parameters
-
tasks | Tasks to be executed |
- Returns
- std::shared_future object
* Since std::packaged_task is a non-copyable object,
* and std::function erases the type information of its arguments, making std::move ineffective on non-copyable objects,
* the solution here is to use std::shared_ptr to wrap std::packaged_task.
*
References postTask().
◆ postTask() [2/3]
void sese::ThreadPool::postTask |
( |
const std::function< void()> & | task | ) |
|
◆ postTask() [3/3]
void sese::ThreadPool::postTask |
( |
const std::vector< std::function< void()> > & | tasks | ) |
|
Add multiple tasks to the thread pool.
- Parameters
-
tasks | Collection of tasks to be executed |
References data.
◆ postTaskEx()
template<typename FUNCTION , typename... ARGS>
void sese::ThreadPool::postTaskEx |
( |
FUNCTION && | f, |
|
|
ARGS &&... | args ) |
|
inline |
Add a task to the thread pool and bind parameters.
- Template Parameters
-
FUNCTION | Function template |
ARGS | Argument template |
- Parameters
-
References f, and postTask().
◆ shutdown()
void sese::ThreadPool::shutdown |
( |
| ) |
|
◆ size()
size_t sese::ThreadPool::size |
( |
| ) |
|
|
nodiscardnoexcept |
◆ data
◆ name
std::string sese::ThreadPool::name |
|
private |
◆ threadGroup
std::vector<Thread *> sese::ThreadPool::threadGroup |
|
private |
◆ threads
size_t sese::ThreadPool::threads = 0 |
|
private |
The documentation for this class was generated from the following files: