Per the java spec, "The load, store, read, and write actions on volatile variables are atomic, even if the type of the variable is double or long." Problem is, atomic in Java does not mean thread safe. I learned this lesson the hard way back when I wrote my own thread factory. Atomic in java means you will never get a mangled value. That is to say that you won't see the value while it's in the process of being changed. For example, if you have a non-volatile long you may get half of it in one state and the other half in a different state.
Bottom line, ++'ing a volatile is always atomic, just not thread safe. I believe that is what you meant to ask yes? I do not recollect any of my code in Fred using volatile. Of what code do you speak? -Pascal On Fri, 16 May 2003 22:57:29 +0100, Toad wrote: > Is ++'ing an integer always atomic in java, assuming the var is declared > volatile? AFAICS, x86 would be atomic... but anything RISC would involve > a separate load and store, right? > > Pascal's code uses this, and I have some local code that uses it... > could be a nice optimization, but if it's wrong, we can't do it. _______________________________________________ devl mailing list devl at freenetproject.org http://hawk.freenetproject.org:8080/cgi-bin/mailman/listinfo/devl
