Logo

Programming-Idioms

History of Idiom 33 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-08-01, 01:54:19

Version 3

2015-08-20, 11:34:09

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.

Code
let mut x=x.lock().unwrap();
*x=f(x);
Comments bubble
Assuming x is created like this:
let x=Mutex::new(0);
Origin
http://doc.rust-lang.org/std/sync/struct.Mutex.html#examples