Skip to content

Instantly share code, notes, and snippets.

@jiacai2050
Created April 18, 2020 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiacai2050/6d41bfcfe11a6e81e3051f089a68e642 to your computer and use it in GitHub Desktop.
Save jiacai2050/6d41bfcfe11a6e81e3051f089a68e642 to your computer and use it in GitHub Desktop.
Example to reproduce stackoverflow error
thread '
thread 'outer-thread-0' has overflowed its stack
fatal runtime error: stack overflow
outer-thread-1' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)
use rayon;
use rayon::prelude::*;
fn main() {
let pool_outer = rayon::ThreadPoolBuilder::new()
.num_threads(2)
.thread_name(|i| format!("outer-thread-{}", i))
.build()
.unwrap();
let pool_inner = rayon::ThreadPoolBuilder::new()
.num_threads(2)
.thread_name(|i| format!("inner-thread-{}", i))
.build()
.unwrap();
pool_outer.scope(|_| {
(0..90000000).into_par_iter().for_each(|out_i| {
pool_inner.scope(|_| {
// rayon::scope(|_| { // rayon::scope doesn't cause stack overflow
let sum: i32 = (0..2000).into_par_iter().map(|i| i + 1).sum();
if out_i == 1 {
println!("sum = {:?}, out_i = {}", sum, out_i);
}
})
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment