Bash++
Bash++ compiler internal documentation
ThreadPool.h
Go to the documentation of this file.
1
6#pragma once
7#include <condition_variable>
8#include <functional>
9#include <mutex>
10#include <queue>
11#include <vector>
12#include <thread>
13
24 private:
25 std::vector<std::thread> workers;
26 std::queue<std::function<void()>> tasks;
27 std::mutex queue_mutex;
28 std::condition_variable condition;
29 bool stop;
30 public:
31 ThreadPool(size_t threads = std::thread::hardware_concurrency());
33
39 void enqueue(std::function<void()> task);
40 void cleanup();
41 size_t getThreadCount() const;
42};
A thread pool implementation that manages a pool of worker threads to execute tasks concurrently.
Definition ThreadPool.h:23
bool stop
Definition ThreadPool.h:29
~ThreadPool()
Definition ThreadPool.cpp:32
void enqueue(std::function< void()> task)
Enqueue a new task to be executed by the thread pool.
Definition ThreadPool.cpp:47
std::condition_variable condition
Definition ThreadPool.h:28
size_t getThreadCount() const
Definition ThreadPool.cpp:65
std::vector< std::thread > workers
Definition ThreadPool.h:25
void cleanup()
Definition ThreadPool.cpp:55
std::mutex queue_mutex
Definition ThreadPool.h:27
std::queue< std::function< void()> > tasks
Definition ThreadPool.h:26