mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user