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() {
|
||||
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!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user