History of Idiom 33 > diff from v12 to v13
Edit summary for version 13 by :
↷
Version 12
2015-10-18, 13:19:52
Version 13
2015-10-29, 14:05:13
Idiom #33 Atomically read and update variable
Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.
Idiom #33 Atomically read and update variable
Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.
Demo URL
https://play.rust-lang.org/?code=use%20std%3A%3Async%3A%3AMutex%3B%0A%0Afn%20f(x%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20x%20%2B%201%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%20Mutex%3A%3Anew(0)%3B%0A%20%20%20%20let%20mut%20x%20%3D%20x.lock().unwrap()%3B%0A%20%20%20%20*x%20%3D%20f(*x)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20*x)%3B%0A%7D%0A&version=stable
Demo URL
https://play.rust-lang.org/?code=use%20std%3A%3Async%3A%3AMutex%3B%0A%0Afn%20f(x%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20x%20%2B%201%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%20Mutex%3A%3Anew(0)%3B%0A%20%20%20%20let%20mut%20x%20%3D%20x.lock().unwrap()%3B%0A%20%20%20%20*x%20%3D%20f(*x)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20*x)%3B%0A%7D%0A&version=stable
Comments bubble
`let x = Mutex::new(0);`
Comments bubble
`let x = Mutex::new(0);`