25 unsigned int iThreadCt = std::thread::hardware_concurrency();
33 for (
unsigned int iCt = 0; iCt < iThreadCt; iCt++) {
50 objThread.request_stop();
59 void submit(std::function<
void()> objJob) {
71 while (!st.stop_requested() && !
m_bDone) {
72 std::function<void()> objJob;
Manages a pool of worker threads that consume tasks from a ThreadSafeQueue. Utilizes C++20 std::jthre...
Definition ThreadPool.h:17
void submit(std::function< void()> objJob)
Submits a void() function/lambda to the pool.
Definition ThreadPool.h:59
std::atomic< bool > m_bDone
Definition ThreadPool.h:87
ThreadSafeQueue< std::function< void()> > m_ObjQueue
Definition ThreadPool.h:88
ThreadPool()
Constructs the thread pool. Defaults to (Hardware Threads - 1) to leave the main thread free.
Definition ThreadPool.h:23
std::vector< std::jthread > m_objJThreads
Definition ThreadPool.h:86
void worker_loop(std::stop_token st)
The main loop for worker threads.
Definition ThreadPool.h:70
~ThreadPool()
Destructor. Stops all threads and joins them.
Definition ThreadPool.h:42
A thread-safe FIFO queue wrapper using mutexes and condition variables. Designed for producer-consume...
Definition ThreadSafeQueue.h:17
void invalidate()
Wakes up all waiting threads effectively cancelling the wait.
Definition ThreadSafeQueue.h:88
bool wait_and_pop(T &objValue)
Waits until the queue is not empty, then pops the front element.
Definition ThreadSafeQueue.h:50
void push(T &&objValue)
Pushes a value into the queue (Move semantics).
Definition ThreadSafeQueue.h:26