Logo

Programming-Idioms

History of Idiom 33 > diff from v4 to v5

Edit summary for version 5 by :

Version 4

2015-08-20, 12:00:38

Version 5

2015-08-20, 18:16:31

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
synchronized x = f(x);
Comments bubble
The synchronized statement can also be written with braces, but for one liners, they can be omitted.

The synchronized statement automatically wraps what ever is in it in a mutex.