Commit 5a90717a authored by Lingxi-Li's avatar Lingxi-Li

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 9b71fc86
...@@ -91,12 +91,10 @@ public: ...@@ -91,12 +91,10 @@ public:
// you can't steal from yourself, can you? // you can't steal from yourself, can you?
return nullptr; return nullptr;
} }
size_t victim; // roll the dice to pick a victim other than ourselves
do { size_t victim = d(self).rengine() % (p->num_workers() - 1);
// roll the dice to pick a victim other than ourselves if (victim == self->id())
victim = d(self).rengine() % p->num_workers(); victim = p->num_workers() - 1;
}
while (victim == self->id());
// steal oldest element from the victim's queue // steal oldest element from the victim's queue
return d(p->worker_by_id(victim)).queue.take_tail(); 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