Skip to content

Commit

Permalink
Day61 added multithreading in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
mishalturkane committed Dec 21, 2024
1 parent 6e0e199 commit 644479d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Day61/rust/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::thread;
use std::time::Duration;

fn main() {
// Create a vector to hold the thread handles
let mut handles = vec![];

// Spawn 5 threads
for i in 1..=5 {
let handle = thread::spawn(move || {
println!("Thread {} is starting.", i);
thread::sleep(Duration::from_secs(2));
println!("Thread {} is done.", i);
});

// Push the handle into the vector
handles.push(handle);
}

// Wait for all threads to finish
for handle in handles {
handle.join().unwrap();
}

println!("All threads have completed.");
}

0 comments on commit 644479d

Please sign in to comment.