Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Created May 5, 2020 18:29
Show Gist options
  • Save bsodmike/a41f55e067292fd32960a9861b19e135 to your computer and use it in GitHub Desktop.
Save bsodmike/a41f55e067292fd32960a9861b19e135 to your computer and use it in GitHub Desktop.
let delay = time::Duration::from_millis(1);
let now = time::Instant::now();
let thread_delay = Arc::new(1);
let mut done = false;
while !done {
let thread_delay = Arc::clone(&thread_delay);
let handle = thread::spawn(move || {
for j in 1..20 {
println!("hi number {} from the spawned thread!", j);
thread::sleep(time::Duration::from_millis(*thread_delay));
}
println!("Thread end: {:#?}", now.elapsed());
});
for i in 1..10 {
println!("hi number {} from the main thread!", i);
thread::sleep(time::Duration::from_millis(1));
}
println!("Loop end: {:#?}", now.elapsed());
handle.join().unwrap();
done = true;
}
println!("Elapsed: {:#?}", now.elapsed());
@bsodmike
Copy link
Author

bsodmike commented May 5, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment