Let\'s say that a class has a public int counter
field that is accessed by multiple threads. This int
is only incremented or decremented.
T
I second Jon Skeet's answer and want to add the following links for everyone who want to know more about "volatile" and Interlocked:
Atomicity, volatility and immutability are different, part one - (Eric Lippert's Fabulous Adventures In Coding)
Atomicity, volatility and immutability are different, part two
Atomicity, volatility and immutability are different, part three
Sayonara Volatile - (Wayback Machine snapshot of Joe Duffy's Weblog as it appeared in 2012)