Last active
January 1, 2016 01:28
-
-
Save jfager/8072694 to your computer and use it in GitHub Desktop.
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
//#[no_uv]; //Works as expected w/ no_uv | |
extern mod std; | |
use std::{rand, task, vec}; | |
use std::rand::Rng; | |
use std::hashmap::HashMap; | |
use std::task::TaskBuilder; | |
pub fn named_task(name: ~str) -> TaskBuilder { | |
let mut ui_task = task::task(); | |
ui_task.name(name); | |
ui_task | |
} | |
fn spawnWithMap(i: int) { | |
do named_task(format!("inner{}", i)).spawn { | |
// Vectors don't have a problem. | |
// let v: ~[int] = vec::with_capacity(100000); | |
// println!("Vec{} created!", i); | |
// HashMaps do. | |
let m: HashMap<~str, ~str> = HashMap::new(); | |
println!("HashMap{} created!", i); | |
// Looks like the HashMap problem stems from the random numbers. | |
//let mut r = rand::task_rng(); | |
//let r1: int = r.gen(); | |
//let r2: int = r.gen(); | |
//println!("Random{} created!", i); | |
} | |
} | |
fn tightloop() { | |
let mut i = 0; | |
while i<1000000000 { | |
i += 1; | |
} | |
println!("Finished tightloop!"); | |
} | |
fn main() { | |
//With the outer task, at least one of the spawnWithMap calls | |
//will not print "HashMapX created!" until after tightloop, regardless | |
//of how long I make tightloop run. But if I comment out the | |
//outer task, they seem to all finish okay. | |
//Creating Vecs seems fine. I'm thinking the issue with HashMaps is | |
//due to the rng stuff it uses. Validated this by just getting some | |
//random numbers, which seems to have the same problem. | |
do named_task(~"outer").spawn { | |
spawnWithMap(1); | |
spawnWithMap(2); | |
spawnWithMap(3); | |
tightloop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment