java - long 和 double 值的原子读写

标签 java multithreading atomic

longdouble 读写操作不是原子的,因为它们的大小超过了 cpu 字的大小。

那么如果我有 64 位机器,我可以得到 longdouble 的原子读写操作吗?

最佳答案

so could i get atomic read and write operation of long and double if i have 64 bit machine ?

答案是“也许”。答案取决于 JVM 实现以及机器架构。引用自Java Language definition 17.7 :

Some implementations may find it convenient to divide a single write action on a 64-bit long or double value into two write actions on adjacent 32-bit values. For efficiency's sake, this behavior is implementation-specific; an implementation of the Java Virtual Machine is free to perform writes to long and double values atomically or in two parts.

Implementations of the Java Virtual Machine are encouraged to avoid splitting 64-bit values where possible. Programmers are encouraged to declare shared 64-bit values as volatile or synchronize their programs correctly to avoid possible complications.

这是关于 Ensure atomicity when reading and writing 64-bit values 的精彩页面.

关于java - long 和 double 值的原子读写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23120811/

相关文章:

java - ImageIcon引用麻烦

Java LibGDX SwingWorker 卡住 GUI( block uploader )

python - django 事务原子性..是信任吗?

python - Django1.6 IntegrityError 尽管有 transaction.atomic()?

java - Eclipse Che 不启动 : 'java.lang.ClassNotFoundException org.apache.juli.ClassLoaderLogManager'

java - 在基于 Web 的 Spring 范围中使用 Thymeleaf 处理 HTML 文件并将处理后的模板存储为字符串

java - 将表单单选值发送到 Java servlet,返回 null

java - 管理使用 Java 访问数据库的线程

c++ - C++ 中的多线程程序显示出与串行程序相同的性能

go - Golang atomic.StorePointer(...)表现异常