From cd83fbcebc1ac672eb955bfdfb74df46240244ac Mon Sep 17 00:00:00 2001 From: Hayden Stainsby Date: Tue, 8 Oct 2024 22:25:48 +0200 Subject: [PATCH] reduce large blocking example size It was causing a stack overflow when run on tokio 1.40.0. --- console-subscriber/examples/app.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/console-subscriber/examples/app.rs b/console-subscriber/examples/app.rs index e341b6e49..688ef6193 100644 --- a/console-subscriber/examples/app.rs +++ b/console-subscriber/examples/app.rs @@ -12,6 +12,8 @@ OPTIONS: burn Includes a (misbehaving) task that spins CPU with self-wakes coma Includes a (misbehaving) task that forgets to register a waker noyield Includes a (misbehaving) task that spawns tasks that never yield + blocking Includes a blocking task that (not misbehaving) + large Includes tasks that are driven by futures that are larger than recommended "#; #[tokio::main] @@ -62,11 +64,7 @@ async fn main() -> Result<(), Box> { // Larger than the release mode auto-boxing limit .spawn(large_future::<20_000>()) .unwrap(); - tokio::task::Builder::new() - .name("huge-blocking-wait") - // Larger than the release mode auto-boxing limit - .spawn(large_blocking::<20_000>()) - .unwrap(); + large_blocking::<20_000>(); } "help" | "-h" => { eprintln!("{}", HELP); @@ -184,19 +182,20 @@ async fn large_future() { } } -async fn large_blocking() { - let numbers = [0_usize; N]; +fn large_blocking() { + let numbers = [0_u8; N]; tokio::task::Builder::new() .name("huge-blocking") .spawn_blocking(move || { let mut numbers = numbers; + loop { for idx in 0..N { - numbers[idx] = idx; + numbers[idx] = (idx % 256) as u8; std::thread::sleep(Duration::from_millis(100)); (0..=idx).for_each(|jdx| { - assert_eq!(numbers[jdx], jdx); + assert_eq!(numbers[jdx], (jdx % 256) as u8); }); } }