Bash++
Bash++ compiler internal documentation
Public Member Functions | Private Attributes | List of all members
ThreadPool Class Reference

A thread pool implementation that manages a pool of worker threads to execute tasks concurrently. More...

#include <ThreadPool.h>

Public Member Functions

 ThreadPool (size_t threads=std::thread::hardware_concurrency())
 
 ~ThreadPool ()
 
void enqueue (std::function< void()> task)
 Enqueue a new task to be executed by the thread pool.
 
void cleanup ()
 
size_t getThreadCount () const
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< std::function< void()> > tasks
 
std::mutex queue_mutex
 
std::condition_variable condition
 
bool stop
 

Detailed Description

A thread pool implementation that manages a pool of worker threads to execute tasks concurrently.

Copyright (C) 2025 Andrew S. Rightenburg Bash++: Bash with classes

By default, the pool is initialized with a number of available worker threads equal to the number of hardware threads available on the system. Tasks can be enqueued to be executed by the worker threads, which will run them concurrently.

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool::ThreadPool ( size_t  threads = std::thread::hardware_concurrency())

Copyright (C) 2025 Andrew S. Rightenburg Bash++: Bash with classes

◆ ~ThreadPool()

ThreadPool::~ThreadPool ( )

Member Function Documentation

◆ cleanup()

void ThreadPool::cleanup ( )

◆ enqueue()

void ThreadPool::enqueue ( std::function< void()>  task)

Enqueue a new task to be executed by the thread pool.

Parameters
taskA function pointer to be excecuted by a worker thread.

◆ getThreadCount()

size_t ThreadPool::getThreadCount ( ) const

Member Data Documentation

◆ condition

std::condition_variable ThreadPool::condition
private

◆ queue_mutex

std::mutex ThreadPool::queue_mutex
private

◆ stop

bool ThreadPool::stop
private

◆ tasks

std::queue<std::function<void()> > ThreadPool::tasks
private

◆ workers

std::vector<std::thread> ThreadPool::workers
private

The documentation for this class was generated from the following files: