Last active
September 24, 2021 14:40
-
-
Save mariot/c838b4590c78dc4d45d4a9f50d29ebee 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
| use std::sync::Mutex; | |
| use std::thread; | |
| fn main() { | |
| let compteur = Mutex::new(0); | |
| let mut manipulateurs = vec![]; | |
| for _ in 0..10 { | |
| let manipulateur = thread::spawn(move || { | |
| let mut nombre = compteur.lock().unwrap(); | |
| *nombre += 1; | |
| }); | |
| manipulateurs.push(manipulateur); | |
| } | |
| for manipulateur in manipulateurs { | |
| manipulateur.join().unwrap(); | |
| } | |
| println!("Resultat : {}", *compteur.lock().unwrap()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment