Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt: worker_threads must be non-zero #2947

Merged
merged 2 commits into from Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions benches/signal.rs
Expand Up @@ -45,9 +45,8 @@ fn many_signals(bench: &mut Bencher) {
let num_signals = 10;
let (tx, mut rx) = mpsc::channel(num_signals);

let rt = runtime::Builder::new_multi_thread()
// Intentionally single threaded to measure delays in propagating wakes
.worker_threads(0)
// Intentionally single threaded to measure delays in propagating wakes
let rt = runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
Expand Down
3 changes: 1 addition & 2 deletions benches/sync_semaphore.rs
Expand Up @@ -49,8 +49,7 @@ fn uncontended_concurrent_multi(b: &mut Bencher) {
}

fn uncontended_concurrent_single(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(0)
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();

Expand Down
5 changes: 5 additions & 0 deletions tokio/src/runtime/builder.rs
Expand Up @@ -198,7 +198,12 @@ impl Builder {
/// // This will run the runtime and future on the current thread
/// rt.block_on(async move {});
/// ```
///
/// # Panic
///
/// This will panic if `val` is not larger than `0`.
pub fn worker_threads(&mut self, val: usize) -> &mut Self {
assert!(val > 0, "Worker threads cannot be set to 0");
self.worker_threads = Some(val);
self
}
Expand Down