It seems that this is the issue of just using volitile (quatation from the second article you gave):
"Note, however, that for a reference type, only the access to the variable itself is volatile - if you write to something within the instance the reference refers to, that write won't be volatile."
That's why you need a lock, but for int's it should be ok.
Reads and writes to an integer field are already atomic. You don't need volatile to change that behavior. You need volatile to prevent compiler and hardware optimizations in special cases.
Scott
http://www.OdeToCode.com/blogs/scott/
http://twitter.com/OdeToCode
Participant
1510 Points
1248 Posts
MVP
Re: Question about volatile keyword
Oct 18, 2006 05:46 PM|bitmask|LINK
It seems that this is the issue of just using volitile (quatation from the second article you gave):
"Note, however, that for a reference type, only the access to the variable itself is volatile - if you write to something within the instance the reference refers to, that write won't be volatile."
That's why you need a lock, but for int's it should be ok.
Reads and writes to an integer field are already atomic. You don't need volatile to change that behavior. You need volatile to prevent compiler and hardware optimizations in special cases.
http://www.OdeToCode.com/blogs/scott/
http://twitter.com/OdeToCode