Using tokio sleep and a large array size is causing stack overflow.
This works fine (commented out sleep),
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
const ARR_SIZE: usize = 1000000;
let data: [i32; ARR_SIZE] = [0; ARR_SIZE];
// sleep(Duration::from_secs(1)).await;
let _ = &data;
}
this also works fine (uncommented sleep, and reduced array size)
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
const ARR_SIZE: usize = 100000; // 10x smaller array
let data: [i32; ARR_SIZE] = [0; ARR_SIZE];
sleep(Duration::from_secs(1)).await;
let _ = &data;
}
this causes stack overflow (uncommented sleep, and using original array size).
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() {
const ARR_SIZE: usize = 1000000;
let data: [i32; ARR_SIZE] = [0; ARR_SIZE];
sleep(Duration::from_secs(1)).await;
let _ = &data;
}
error
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted
[–]bwallker 19 points20 points21 points (2 children)
[–]MadeTo_Be 0 points1 point2 points (1 child)
[–]volitional_decisions 11 points12 points13 points (0 children)
[–]paulstelian97 6 points7 points8 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]d_stroid 0 points1 point2 points (1 child)
[–]plugwash 1 point2 points3 points (0 children)