sleep sort

This commit is contained in:
2020-05-01 21:03:10 +08:00
parent bd1e807083
commit 521b23770c

View File

@@ -1,10 +1,20 @@
use std::thread;
use std::{ thread, time::Duration, };
// https://zhuanlan.zhihu.com/p/89716165
// sleep sort
fn main() {
let child = thread::spawn(move || {
println!("Hello World!");
});
let _res = child.join().unwrap();
let in_vec = vec![2, 1, 5, 10, 7];
let mut all_threads = vec![];
for i in in_vec {
let child = thread::spawn(move || {
thread::sleep(Duration::from_millis(i));
println!(">> {}", i);
});
all_threads.push(child);
}
for t in all_threads {
t.join().ok();
}
println!("Finished!");
}