diff --git a/Eigen/src/ThreadPool/NonBlockingThreadPool.h b/Eigen/src/ThreadPool/NonBlockingThreadPool.h index 65a222c74..5c18366c7 100644 --- a/Eigen/src/ThreadPool/NonBlockingThreadPool.h +++ b/Eigen/src/ThreadPool/NonBlockingThreadPool.h @@ -42,7 +42,11 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { : env_(env), num_threads_(num_threads), allow_spinning_(allow_spinning), - spin_count_(0), + spin_count_( + // TODO(dvyukov,rmlarsen): The time spent in NonEmptyQueueIndex() is proportional to num_threads_ and + // we assume that new work is scheduled at a constant rate, so we divide `kSpintCount` by number of + // threads and number of spinning threads. The constant was picked based on a fair dice roll, tune it. + allow_spinning && num_threads > 0 ? kSpinCount / kMaxSpinningThreads / num_threads : 0), thread_data_(num_threads), all_coprimes_(num_threads), waiters_(num_threads), @@ -311,7 +315,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { Environment env_; const int num_threads_; const bool allow_spinning_; - int spin_count_; + const int spin_count_; MaxSizeVector thread_data_; MaxSizeVector> all_coprimes_; MaxSizeVector waiters_; @@ -346,12 +350,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { pt->pool = this; pt->rand = GlobalThreadIdHash(); pt->thread_id = thread_id; - // TODO(dvyukov,rmlarsen): The time spent in NonEmptyQueueIndex() is - // proportional to num_threads_ and we assume that new work is scheduled - // at a constant rate, so we divide `kSpintCount` by number of threads - // and number of spinning threads. The constant was picked based on a - // fair dice roll, tune it. - spin_count_ = allow_spinning_ && num_threads_ > 0 ? kSpinCount / kMaxSpinningThreads / num_threads_ : 0; Task t; while (!cancelled_.load(std::memory_order_relaxed)) { MaybeGetTask(&t);