diff --git a/G-concurrency/threads.rs b/G-concurrency/threads.rs new file mode 100644 index 0000000..f62668d --- /dev/null +++ b/G-concurrency/threads.rs @@ -0,0 +1,25 @@ +use std::thread; + +fn main() { + // 1. Spawn the first thread + let handle1 = thread::spawn(|| { + let mut my_number = 0; // Starts at 0 + for _ in 0..10 { + my_number += 1; + println!("Thread 1, Number {}", my_number); + } + }); + + // 2. Spawn the second thread + let handle2 = thread::spawn(|| { + let mut my_number = 0; + for _ in 0..10 { + my_number += 1; + println!("Thread 2, Number {}", my_number); + } + }); + + // 3. Wait for both threads to finish + handle1.join().unwrap(); + handle2.join().unwrap(); +} \ No newline at end of file