Commit 14ab6004 authored by Dominik Charousset's avatar Dominik Charousset

Make sure workers don't pick themselves as victim

parent 9edcd6e1
......@@ -94,7 +94,12 @@ class work_stealing {
template <class Worker>
resumable* try_steal(Worker* self) {
auto p = self->parent();
auto victim = d(self).rengine() % p->num_workers();
size_t victim;
do {
// roll the dice to pick a victim other than ourselves
victim = d(self).rengine() % p->num_workers();
}
while (victim == self->id());
return d(p->worker_by_id(victim)).exposed_queue.try_pop();
}
......@@ -122,10 +127,11 @@ class work_stealing {
// this means we are going to put this job to the very end of our queue
// by moving everything from the exposed to private queue first and
// then enqueue job to the exposed queue
resumable* ptr = d(self).exposed_queue.try_pop();
while (ptr) {
auto next = [&] {
return d(self).exposed_queue.try_pop();
};
for (auto ptr = next(); ptr != nullptr; ptr = next()) {
d(self).private_queue.push_front(ptr);
ptr = d(self).exposed_queue.try_pop();
}
d(self).exposed_queue.push_back(job);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment