是的。有没改良的法。此处的volatile 仅做个标记吧。 java.util.concurrent.atomic.AtomicLong 也是这么写的 private volatile long value;
=====Java Concurrency in Practice====== 3.1.2. Nonatomic 64-bit Operations ........ Out-of-thin-air safety applies to all variables, with one exception: 64-bit numeric variables (double and long) that are not declared volatile (see Section 3.1.4). The Java Memory Model requires fetch and store operations to be atomic, but for nonvolatile long and double variables, the JVM is permitted to treat a 64-bit read or write as two separate 32-bit operations. If the reads and writes occur in different threads, it is therefore possible to read a nonvolatile long and get back the high 32 bits of one value and the low 32 bits of another.[3] Thus, even if you don't care about stale values, it is not safe to use shared mutable long and double variables in multithreaded programs unless they are declared volatile or guarded by a lock.
回复 徐敬琪 2011年03月03日 星期四 16:05
vo
对于l
回复 史荣久 2011年03月03日 星期四 16:28
ja
也是这
p
=====Java Concurrency in Pract
3.1.
....
回复 徐敬琪 2011年03月03日 星期四 17:21
> 恩,此说法有误。
回复 达伦王 2011年03月03日 星期四 17:38
这个是我的理解 :-)