Created
April 18, 2020 02:50
-
-
Save jiacai2050/6d41bfcfe11a6e81e3051f089a68e642 to your computer and use it in GitHub Desktop.
Example to reproduce stackoverflow error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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