在Java中写long和double不是原子的? [英] Writing long and double is not atomic in Java?

查看:79
本文介绍了在Java中写long和double不是原子的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


读取和写入单个变量是原子的(语言保证!),除非变量类型为long或double。

Reading and writing of a single variable is atomic (language guarantee!), unless the variable is of type long or double.

我正在阅读课程的幻灯片,我发现写了。这个类是关于并发的。

I was reading a course's slides and I found that written. The class was about concurrency.

任何人都可以向我解释为什么写一个long或double不是一个原子操作?这真的让我吃惊。

Can anyone explain to me why writing a long or a double is not an atomic operation? It really took me by surprise.

推荐答案

它不是原子的,因为它是一个多步操作在机器代码级别。也就是说,longs和doubles比处理器的字长更长。

It's not atomic because it's a multiple-step operation at the machine code level. That is, longs and doubles are longer than the processor's word length.

这篇关于在Java中写long和double不是原子的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆