mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-23 11:48:09 -05:00
9bdb0a12e4
Hints are now accessible using the CLI subcommand `rustlings hint <exercise name`. BREAKING CHANGE: This fundamentally changes the way people interact with exercises.
29 lines
864 B
Rust
29 lines
864 B
Rust
// threads1.rs
|
|
// Make this compile! Execute `rustlings hint threads1` for hints :)
|
|
// The idea is the thread spawned on line 19 is completing jobs while the main thread is
|
|
// monitoring progress until 10 jobs are completed. If you see 6 lines
|
|
// of "waiting..." and the program ends without timing out when running,
|
|
// you've got it :)
|
|
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
struct JobStatus {
|
|
jobs_completed: u32,
|
|
}
|
|
|
|
fn main() {
|
|
let status = Arc::new(JobStatus { jobs_completed: 0 });
|
|
let status_shared = status.clone();
|
|
thread::spawn(move || {
|
|
for _ in 0..10 {
|
|
thread::sleep(Duration::from_millis(250));
|
|
status_shared.jobs_completed += 1;
|
|
}
|
|
});
|
|
while status.jobs_completed < 10 {
|
|
println!("waiting... ");
|
|
thread::sleep(Duration::from_millis(500));
|
|
}
|
|
}
|