Skip to content

Commit

Permalink
reduce large blocking example size
Browse files Browse the repository at this point in the history
It was causing a stack overflow when run on tokio 1.40.0.
  • Loading branch information
hds committed Oct 8, 2024
1 parent 31bfb7a commit cd83fbc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions console-subscriber/examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -62,11 +64,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// 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);
Expand Down Expand Up @@ -184,19 +182,20 @@ async fn large_future<const N: usize>() {
}
}

async fn large_blocking<const N: usize>() {
let numbers = [0_usize; N];
fn large_blocking<const N: usize>() {
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);
});
}
}
Expand Down

0 comments on commit cd83fbc

Please sign in to comment.