diff --git a/src/advance/concurrency-with-threads/sync1.md b/src/advance/concurrency-with-threads/sync1.md index a37ac58a..b54380b5 100644 --- a/src/advance/concurrency-with-threads/sync1.md +++ b/src/advance/concurrency-with-threads/sync1.md @@ -456,18 +456,15 @@ fn main() { let ccond = cond.clone(); let hdl = spawn(move || { - let mut m = { *cflag.lock().unwrap() }; + let mut lock = cflag.lock().unwrap(); let mut counter = 0; while counter < 3 { - while !m { - m = *ccond.wait(cflag.lock().unwrap()).unwrap(); - } - - { - m = false; - *cflag.lock().unwrap() = false; + while !*lock { + lock = ccond.wait(lock).unwrap(); } + + *lock = false; counter += 1; println!("inner counter: {}", counter);