mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
rt: use task::Inject with current_thread scheduler (#5702)
Previously, the current_thread scheduler used its own injection queue instead of sharing the same one as the multi-threaded scheduler. This patch updates the current_thread scheduler to use the same injection queue as the multi-threaded one (`task::Inject`). `task::Inject` includes an optimization where it does not need to acquire the mutex if the queue is empty.
This commit is contained in:
@@ -1317,4 +1317,39 @@ rt_test! {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os="wasi"))]
|
||||
fn shutdown_concurrent_spawn() {
|
||||
const NUM_TASKS: usize = 10_000;
|
||||
for _ in 0..5 {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let rt = rt();
|
||||
|
||||
let mut txs = vec![];
|
||||
|
||||
for _ in 0..NUM_TASKS {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
txs.push(tx);
|
||||
rt.spawn(async move {
|
||||
rx.await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
// Prime the tasks
|
||||
rt.block_on(async { tokio::task::yield_now().await });
|
||||
|
||||
let th = std::thread::spawn(move || {
|
||||
tx.send(()).unwrap();
|
||||
for tx in txs.drain(..) {
|
||||
let _ = tx.send(());
|
||||
}
|
||||
});
|
||||
|
||||
rx.recv().unwrap();
|
||||
drop(rt);
|
||||
|
||||
th.join().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user