Commit 34e25fa4 authored by Lingxi-Li's avatar Lingxi-Li Committed by Dominik Charousset

Improve `policy::work_stealing::try_steal()`

Victim selection is made collision-free. A try-loop is no longer
needed. In previous version, with two workers, the probability of
collision is 50%!
parent 564001ba
......@@ -91,12 +91,10 @@ public:
// you can't steal from yourself, can you?
return nullptr;
}
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());
// roll the dice to pick a victim other than ourselves
size_t victim = d(self).rengine() % (p->num_workers() - 1);
if (victim == self->id())
victim = p->num_workers() - 1;
// steal oldest element from the victim's queue
return d(p->worker_by_id(victim)).queue.take_tail();
}
......
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