56 stop.store(
true, std::memory_order_release);
58 for (
size_t i = 0; i <
threads.size(); ++i)
65 if (
threads.size() < num_threads)
68 for (
size_t i = 0; i < num_threads; ++i)
76 tasks.push_back(task);
87 std::unique_lock<std::mutex> lock(tp->
mutex);
92 if(tp->
stop.load(std::memory_order_acquire))
96 if (!tp->
tasks.empty())
98 task = tp->
tasks.front();
99 tp->
tasks.pop_front();
Implements a pool of threads, and can queue tasks.
std::vector< std::thread > threads
static void start_thread(thread_pool *tp)
A static function to start a thread.
std::condition_variable condition
~thread_pool()
default destructor
std::deque< worker_thread_base * > tasks
void add_task(worker_thread_base *task)
Adds a task to the thread pool.
void init(size_t num_threads)
Initializes the thread pool.
A base object for queuing tasks in the thread_pool.
virtual void execute()=0
Derived functions must define this function to execute its work.