Created
May 5, 2020 18:29
-
-
Save bsodmike/a41f55e067292fd32960a9861b19e135 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3b3d8e740c90a0986ba1fe5c5c14c364
https://doc.rust-lang.org/book/ch16-01-threads.html