Fix bug related to spawning optimization (#375)

The thread pool optimizes cases where a task currently running on the
pool spawns a new future. However, the optimization did not factor in
cases where two thread pools interacted.

This patch fixes the optimization and includes a test.

Fixes #342
This commit is contained in:
Carl Lerche
2018-05-24 22:06:32 -07:00
committed by GitHub
parent 96f3ec903c
commit 4af6109398
2 changed files with 54 additions and 7 deletions
+26
View File
@@ -560,3 +560,29 @@ fn panic_in_task() {
await_shutdown(pool.shutdown_on_idle());
}
#[test]
fn multi_threadpool() {
use futures::sync::oneshot;
let pool1 = ThreadPool::new();
let pool2 = ThreadPool::new();
let (tx, rx) = oneshot::channel();
let (done_tx, done_rx) = mpsc::channel();
pool2.spawn({
rx.and_then(move |_| {
done_tx.send(()).unwrap();
Ok(())
})
.map_err(|e| panic!("err={:?}", e))
});
pool1.spawn(lazy(move || {
tx.send(()).unwrap();
Ok(())
}));
done_rx.recv().unwrap();
}