Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Concurrent-computing/Rust/concurrent-computing.rust
Normal file
18
Task/Concurrent-computing/Rust/concurrent-computing.rust
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extern crate rand; // not needed for recent versions
|
||||
use std::thread;
|
||||
use rand::thread_rng;
|
||||
use rand::distributions::{Range, IndependentSample};
|
||||
|
||||
fn main() {
|
||||
let mut rng = thread_rng();
|
||||
let rng_range = Range::new(0u32, 100);
|
||||
for word in "Enjoy Rosetta Code".split_whitespace() {
|
||||
let snooze_time = rng_range.ind_sample(&mut rng);
|
||||
let local_word = word.to_owned();
|
||||
std::thread::spawn(move || {
|
||||
thread::sleep_ms(snooze_time);
|
||||
println!("{}", local_word);
|
||||
});
|
||||
}
|
||||
thread::sleep_ms(1000);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue