bangerth / spec-cpuv8-sampleflow

A benchmark for the SPEC CPUv8 test suite based on the deal.II and SampleFlow libraries
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Fix thread pool #22

Closed bangerth closed 1 year ago

bangerth commented 1 year ago

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.)

bangerth commented 1 year ago

Fixed by e6c7bbb.