19 }
catch (
const std::exception &e) {
20 LOG_ERROR(
"ThreadPool destructor caught exception: ", e.what());
35 _workers.emplace_back([
this, i](std::stop_token stopToken) {
36 LOG_DEBUG(
"Worker thread ", i,
" started (TID: ", std::this_thread::get_id(),
")");
38 LOG_DEBUG(
"Worker thread ", i,
" exiting");
54 worker.request_stop();
70 LOG_WARNING(
"Enqueuing task to stopped ThreadPool - task will not execute");
87 while (!stopToken.stop_requested()) {
98 }
catch (
const std::exception &e) {
99 LOG_ERROR(
"Worker thread caught exception: ", e.what());
101 LOG_ERROR(
"Worker thread caught unknown exception");
T pop()
Pop an item, blocking until one is available.
void push(T item)
Push an item to the queue.
std::function< void()> Task
size_t size() const override
Get the number of threads in the pool.
std::vector< std::jthread > _workers
void stop() override
Stop all threads and clean up resources.
void _workerLoop(std::stop_token stopToken)
Worker thread main loop Continuously pulls tasks from the queue and executes them.
void enqueue(Task task) override
Enqueue a task to be executed by the thread pool.
void start() override
Start all threads in the pool.
ThreadPool(size_t threadCount)
ThreadSafeQueue< Task > _taskQueue