threadpool: spawn new tasks onto a random worker (#683)

* threadpool: submit new tasks to a random worker

* Revert unnecessary version bumps
This commit is contained in:
Stjepan Glavina
2018-10-03 23:09:20 +02:00
committed by GitHub
parent d35d0518f5
commit e27b0a46ba
5 changed files with 146 additions and 40 deletions
+10
View File
@@ -317,6 +317,16 @@ impl Pool {
// All workers are active, so pick a random worker and submit the
// task to it.
self.submit_to_random(task, inner);
}
/// Submit a task to a random worker
///
/// Called from outside of the scheduler, this function is how new tasks
/// enter the system.
pub fn submit_to_random(&self, task: Arc<Task>, inner: &Arc<Pool>) {
debug_assert_eq!(*self, **inner);
let len = self.workers.len();
let idx = self.rand_usize() % len;