You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This program in particular gives me the error stack overflow detected, size=4096, but if I try to do something more elaborated using shared access to entries it also raises some address boundary errors.
The interesting part is that this single combination is failing but if I use the crates separately they work fine:
// This will workstaticrefDATA:Vec<u8> = vec![123];// Or thislet data = vec![rand::random::<u8>()];let task = go!(...);
I'm using may 0.2.0 and rand 0.4.2.
The text was updated successfully, but these errors were encountered:
rand is using a big stack size in it's implementation.
for debug version stack usage
coroutine name = None, stack size = 40959, used size = 9205
for release version
coroutine name = None, stack size = 40959, used size = 2740
here is the modified test
#[macro_use]externcrate lazy_static;#[macro_use]externcrate may;externcrate rand;use std::io::Read;use std::collections::HashMap;// the ThreadRng is using a big stack!lazy_static!{static ref DATA: Vec<u8> = vec![rand::random::<u8>()];
}// the OsRng is not using a big stack, you can safely use it in coroutine context/*lazy_static! { static ref DATA: Vec<u8> = { use rand::Rng; let mut rand = rand::OsRng::new().unwrap(); vec![rand.gen()] };}*/fnmain(){
may::config().set_stack_size(4096*10 - 1);letmut entries:HashMap<usize,Vec<u8>> = HashMap::new();// force init DATA in the main thread// let _ = DATA[0];let task = go!(move || {
entries.insert(0, DATA.clone());
});
task.join().unwrap();
std::io::stdin().read(&mut[0]).ok();}
the solution is init the DATA in main thread (not in the coroutine context, just like what you did to pass the test), or use the os rand interface which doesn't use a huge stack.
Now it makes perfect sense. Static values declared with lazy_static! only get evaluated once the value is used, that's why lazy (d'oh), and if it's being used inside the coroutine context it also affect's it's stack. I'm such a noob.
I'm trying to understand why this small program is failing to run:
This program in particular gives me the error
stack overflow detected, size=4096
, but if I try to do something more elaborated using shared access toentries
it also raises some address boundary errors.The interesting part is that this single combination is failing but if I use the crates separately they work fine:
I'm using may
0.2.0
and rand0.4.2
.The text was updated successfully, but these errors were encountered: