mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Fix potential data race on spin_count_
NonBlockingThreadPool member variable
This commit is contained in:
parent
bc67025ba7
commit
5d866a7a78
@ -42,7 +42,11 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
: env_(env),
|
: env_(env),
|
||||||
num_threads_(num_threads),
|
num_threads_(num_threads),
|
||||||
allow_spinning_(allow_spinning),
|
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),
|
thread_data_(num_threads),
|
||||||
all_coprimes_(num_threads),
|
all_coprimes_(num_threads),
|
||||||
waiters_(num_threads),
|
waiters_(num_threads),
|
||||||
@ -311,7 +315,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
Environment env_;
|
Environment env_;
|
||||||
const int num_threads_;
|
const int num_threads_;
|
||||||
const bool allow_spinning_;
|
const bool allow_spinning_;
|
||||||
int spin_count_;
|
const int spin_count_;
|
||||||
MaxSizeVector<ThreadData> thread_data_;
|
MaxSizeVector<ThreadData> thread_data_;
|
||||||
MaxSizeVector<MaxSizeVector<unsigned>> all_coprimes_;
|
MaxSizeVector<MaxSizeVector<unsigned>> all_coprimes_;
|
||||||
MaxSizeVector<EventCount::Waiter> waiters_;
|
MaxSizeVector<EventCount::Waiter> waiters_;
|
||||||
@ -346,12 +350,6 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
pt->pool = this;
|
pt->pool = this;
|
||||||
pt->rand = GlobalThreadIdHash();
|
pt->rand = GlobalThreadIdHash();
|
||||||
pt->thread_id = thread_id;
|
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;
|
Task t;
|
||||||
while (!cancelled_.load(std::memory_order_relaxed)) {
|
while (!cancelled_.load(std::memory_order_relaxed)) {
|
||||||
MaybeGetTask(&t);
|
MaybeGetTask(&t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user