Threading::ThreadPool class

Allows to execute tasks in multithread manner.

It is not allowed to use thread pool in multiple threads. It is guaranteed tasks process-start times and ordered as their add time.

Public types

using Task = std::function<void()>

Constructors, destructors, conversion operators

ThreadPool(size_t useThreads) explicit
Create thread pool with specified number of threads.
ThreadPool(const ThreadPool& other) deleted
ThreadPool(ThreadPool&& other) deleted
~ThreadPool()
Custom destructor which are to stop workers.

Public functions

auto operator=(const ThreadPool& other) -> ThreadPool& deleted
auto operator=(ThreadPool&& other) -> ThreadPool& deleted
void submit(Task task)
Schedule task on execution.
void wait()
Wait for all spawned for now tasks complete.
void stop()
Stop workers.

Function documentation

void Threading::ThreadPool::stop()

Stop workers.

Some tasks can be incomplete. Blocks until every thread won't be stopped and destroyed. After that, thread pool can not process new tasks.