sleep sort
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
use std::thread;
|
use std::{ thread, time::Duration, };
|
||||||
|
|
||||||
// https://zhuanlan.zhihu.com/p/89716165
|
// sleep sort
|
||||||
fn main() {
|
fn main() {
|
||||||
let child = thread::spawn(move || {
|
let in_vec = vec![2, 1, 5, 10, 7];
|
||||||
println!("Hello World!");
|
|
||||||
});
|
let mut all_threads = vec![];
|
||||||
let _res = child.join().unwrap();
|
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!");
|
println!("Finished!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user