From dc16e35f98955d2a28d49ad01791dcc2c9c8178f Mon Sep 17 00:00:00 2001 From: Mike Ton Date: Wed, 19 Jul 2023 16:30:28 +0000 Subject: [PATCH 1/2] Update loop to Result: 10 --- .../ch16-fearless-concurrency/listing-16-15/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs index 30247dd52f..a568668d56 100644 --- a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs @@ -5,7 +5,13 @@ fn main() { let counter = Arc::new(Mutex::new(0)); let mut handles = vec![]; - for _ in 0..10 { + // The chapters accompanying text states that the print should be : + // Result: 10 + // But the current code yields : + // Result: 9 + // An update to this should resolve the drift between text and code : + // 1..=10 - is a range that is inclusive of 1 and inclusive of 10 + for _ in 0..=10 { let counter = Arc::clone(&counter); let handle = thread::spawn(move || { let mut num = counter.lock().unwrap(); From a80a425f71f0849af91be3d7d19df7f6ed99cc4b Mon Sep 17 00:00:00 2001 From: Mike Ton Date: Wed, 19 Jul 2023 16:46:31 +0000 Subject: [PATCH 2/2] Comments cleaned up and removed --- .../ch16-fearless-concurrency/listing-16-15/src/main.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs index a568668d56..6e849ff117 100644 --- a/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs +++ b/listings/ch16-fearless-concurrency/listing-16-15/src/main.rs @@ -5,12 +5,6 @@ fn main() { let counter = Arc::new(Mutex::new(0)); let mut handles = vec![]; - // The chapters accompanying text states that the print should be : - // Result: 10 - // But the current code yields : - // Result: 9 - // An update to this should resolve the drift between text and code : - // 1..=10 - is a range that is inclusive of 1 and inclusive of 10 for _ in 0..=10 { let counter = Arc::clone(&counter); let handle = thread::spawn(move || {