mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
rt: fix default thread number logic (#2457)
Previously, the function picking the default number of threads for the threaded runtime did not factor in `max_threads`. Instead, it only used the value returned by `num_cpus`. However, if `num_cpus` returns a value greater than `max_threads`, then the function would panic. This patch fixes the function by limiting the default number of threads by `max_threads`. Fixes #2452
This commit is contained in:
@@ -322,6 +322,16 @@ fn multi_threadpool() {
|
||||
done_rx.recv().unwrap();
|
||||
}
|
||||
|
||||
// Testing this does not panic
|
||||
#[test]
|
||||
fn max_threads() {
|
||||
let _rt = tokio::runtime::Builder::new()
|
||||
.threaded_scheduler()
|
||||
.max_threads(1)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn rt() -> Runtime {
|
||||
Runtime::new().unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user