Right now, when a worker thread is available, it moves a task out of the queue and works on it. But ThreadPool::join_all() only tests whether the queue is empty or not:
void ThreadPool::join_all()
{
if (concurrency >= 2)
{
// Wait for all currently enqueued tasks to finish. Do this by <--- not actually true
// repeatedly getting the lock and checking the size of the
// queue. If it is zero, return. If it is nonzero, tell the OS to
// do something else instead.
while (true)
{
{
std::lock_guard<std::mutex> lock(queue_mutex);
if (task_queue.empty())
return;
}
std::this_thread::yield();
}
}
}
It doesn't check whether the tasks have actually been finished. This should be fixed.
(The destructor of the class is correct, though: It checks that all worker threads have terminated.)
Right now, when a worker thread is available, it moves a task out of the queue and works on it. But
ThreadPool::join_all()
only tests whether the queue is empty or not:It doesn't check whether the tasks have actually been finished. This should be fixed.
(The destructor of the class is correct, though: It checks that all worker threads have terminated.)