Class ThreadPool#

Inheritance Relationships#

Base Type#

  • public std::enable_shared_from_this< ThreadPool >

Class Documentation#

class ThreadPool : public std::enable_shared_from_this<ThreadPool>#

Holds a pool of threads that can be used to execute tasks in parallel.

Public Functions

ThreadPool() = default#

ThreadPool constructor. The constructor is not meant to be called directly. Please use the create(…) method instead to create an instance.

void addTask(const std::function<void()> &task)#

Add task to the back of the queue.

Parameters:

task – The task to be completed.

void addPriorityTask(const std::function<void()> &task)#

Add task to the front of the queue.

Parameters:

task – The task to be completed.

void setThreadPoolSize(size_t num_threads)#

Set the number of worker threads in the pool.

Parameters:

num_threads – The size of the thread pool.

size_t getThreadPoolSize()#

Get the number of workers in the thread pool.

Returns:

The number of workers in the thread pool.

~ThreadPool()#

Destructor.

Public Static Functions

static const ks_ptr<ThreadPool> &singleton()#

Get the global ThreadPool instance.

Returns:

The ThreadPool

static ks_ptr<ThreadPool> create()#

Create a new ThreadPool instance.

Returns:

The newly created ThreadPool instance.