Skip to content

Instantly share code, notes, and snippets.

@ggssh
Created September 14, 2024 08:10
Show Gist options
  • Save ggssh/1f7c9e01c060b3b3f211c486e143e895 to your computer and use it in GitHub Desktop.
Save ggssh/1f7c9e01c060b3b3f211c486e143e895 to your computer and use it in GitHub Desktop.
Sleep Sort
fn sleep_sort(arr: &mut [u64]) {
let (s, r) = std::sync::mpsc::channel();
for &n in arr {
let s = s.clone();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(n));
s.send(n).unwrap();
});
}
*arr = r.iter().collect::<Vec<_>>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment