java volatile double、long的原子性
来源:互联网 发布:pkpm建筑设计软件 编辑:程序博客网 时间:2024/05/17 02:31
同步和Java内存模型 (二)原子性
原文:http://gee.cs.oswego.edu/dl/cpj/jmm.html 第二章
作者:Doug Lea 译者:程晓明 校对:方腾飞
除了long型字段和double型字段外,java内存模型确保访问任意类型字段所对应的内存单元都是原子的。这包括引用其它对象的引用类型的字段。此外,volatile long 和volatile double也具有原子性 。(虽然java内存模型不保证non-volatile long 和 non-volatile double的原子性,当然它们在某些场合也具有原子性。)(译注:non-volatile long在64位JVM,OS,CPU下具有原子性)
当在一个表达式中使用一个non-long或者non-double型字段时,原子性可以确保你将获得这个字段的初始值或者某个线程对这个字段写入之后的值;但不会是两个或更多线程在同一时间对这个字段写入之后产生混乱的结果值(即原子性可以确保,获取到的结果值所对应的所有bit位,全部都是由单个线程写入的)。但是,如下面(译注:指可见性章节)将要看到的,原子性不能确保你获得的是任意线程写入之后的最新值。 因此,原子性保证通常对并发程序设计的影响很小。
原文
Atomicity
Accesses and updates to the memory cells corresponding to fields of any type except long or double are guaranteed to be atomic. This includes fields serving as references to other objects. Additionally, atomicity extends to volatile long and double. (Even though non-volatile longs and doubles are not guaranteed atomic, they are of course allowed to be.)
Atomicity guarantees ensure that when a non-long/double field is used in an expression, you will obtain either its initial value or some value that was written by some thread, but not some jumble of bits resulting from two or more threads both trying to write values at the same time. However, as seen below, atomicity alone does not guarantee that you will get the value most recently written by any thread. For this reason, atomicity guarantees per se normally have little impact on concurrent program design.
原文:http://gee.cs.oswego.edu/dl/cpj/jmm.html 第二章
作者:Doug Lea 译者:程晓明 校对:方腾飞
除了long型字段和double型字段外,java内存模型确保访问任意类型字段所对应的内存单元都是原子的。这包括引用其它对象的引用类型的字段。此外,volatile long 和volatile double也具有原子性 。(虽然java内存模型不保证non-volatile long 和 non-volatile double的原子性,当然它们在某些场合也具有原子性。)(译注:non-volatile long在64位JVM,OS,CPU下具有原子性)
当在一个表达式中使用一个non-long或者non-double型字段时,原子性可以确保你将获得这个字段的初始值或者某个线程对这个字段写入之后的值;但不会是两个或更多线程在同一时间对这个字段写入之后产生混乱的结果值(即原子性可以确保,获取到的结果值所对应的所有bit位,全部都是由单个线程写入的)。但是,如下面(译注:指可见性章节)将要看到的,原子性不能确保你获得的是任意线程写入之后的最新值。 因此,原子性保证通常对并发程序设计的影响很小。
原文
Atomicity
Accesses and updates to the memory cells corresponding to fields of any type except long or double are guaranteed to be atomic. This includes fields serving as references to other objects. Additionally, atomicity extends to volatile long and double. (Even though non-volatile longs and doubles are not guaranteed atomic, they are of course allowed to be.)
Atomicity guarantees ensure that when a non-long/double field is used in an expression, you will obtain either its initial value or some value that was written by some thread, but not some jumble of bits resulting from two or more threads both trying to write values at the same time. However, as seen below, atomicity alone does not guarantee that you will get the value most recently written by any thread. For this reason, atomicity guarantees per se normally have little impact on concurrent program design.
- java volatile double、long的原子性
- Java的long、double类型的原子性读取问题
- volatile能保证long&double类型变量操作的原子性
- 证明32位java对long和double的写操作不是原子性的
- java中long和double类型操作的非原子性探究
- java中long和double类型操作的非原子性探究
- long和double类型变量的非原子性
- 非原子的double和long
- long/double volatile
- java int short long float double 类型描述以及原子性说明
- Long与double操作并不是原子的
- volatile的原子性机制
- JAVA拾遗 - volatile关键字和原子性的探讨
- Java:java的原子操作和volatile
- java的原子操作和volatile
- volatile AtomicInteger java多线程操作 原子性
- java原子性以及关键字volatile、synchronized
- Java volatile变量原子性讨论
- android分析windowManager、window、viewGroup之间关系
- 建造者模式
- 从今天开始
- bzoj3669 魔法森林(NOI 2014)
- What are some of the differences between using recursion to solve a problem versus using iteration?
- java volatile double、long的原子性
- 平均一个集合为几个集合
- #DOM操作
- php历史版本页面
- 在C#应用中使用Matlab函数
- tar加减号时的作用 tar cf - | tar xf - 管道 linux
- Android 开发 调用图库选择图片实现和参数详解
- Restful Web Services
- 制作ubuntu的盘启动盘