33#include <condition_variable>
82 for (
size_t i = 0; i < num_threads; ++i) {
95 task = std::move(
tasks_.front());
134 for (std::thread& worker :
workers_) {
135 if (worker.joinable())
157 tasks_.emplace(std::forward<F>(task));
Simple, non-stealing thread pool implementation using a single shared task queue.
Definition tec_thread_pool.hpp:53
std::function< void()> TaskFunc
Type alias for the task function objects stored and executed by the pool.
Definition tec_thread_pool.hpp:56
std::queue< TaskFunc > tasks_
Thread-safe queue of pending tasks (protected by queue_mutex_)
Definition tec_thread_pool.hpp:61
constexpr size_t get_num_threads()
Returns the number of worker threads in this pool.
Definition tec_thread_pool.hpp:112
size_t num_threads_
Number of worker threads in the pool (set during construction)
Definition tec_thread_pool.hpp:59
std::atomic< bool > stop_
Atomic flag used to signal all worker threads to terminate.
Definition tec_thread_pool.hpp:64
ThreadPool(size_t num_threads)
Constructs a thread pool with the specified number of worker threads.
Definition tec_thread_pool.hpp:74
std::condition_variable condition_
Condition variable used to wake up sleeping worker threads when tasks arrive.
Definition tec_thread_pool.hpp:63
virtual ~ThreadPool()
Destructor – gracefully shuts down the thread pool.
Definition tec_thread_pool.hpp:128
std::mutex queue_mutex_
Mutex protecting access to the tasks_ queue.
Definition tec_thread_pool.hpp:62
std::vector< std::thread > workers_
Container holding all worker std::thread objects.
Definition tec_thread_pool.hpp:60
void enqueue(F &&task)
Enqueues a new task to be executed by one of the worker threads.
Definition tec_thread_pool.hpp:154
#define TEC_ENTER(name)
Logs an entry message for a named context (e.g., function).
Definition tec_trace.hpp:211
#define TEC_TRACE(...)
Logs a formatted trace message.
Definition tec_trace.hpp:222
Common definitions and utilities for the tec namespace.
Provides a thread-safe tracing utility for debugging in the tec namespace.