多核与单处理器中的易失性关键字? [英] Volatile keyword in multicore vs single processor?

查看:79
本文介绍了多核与单处理器中的易失性关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听过很多人说volatile关键字在多核处理器中更有意义 比单核处理器要多,但不知道原因.我试图用Google搜索,但没有帮助 这方面.有什么理由吗?

I have heard many people saying that volatile keyword makes more sense in multicore processor than single core processor but don't know the reason. I tried to google but did not help in this aspect. Any reason for it?

根据我的理解,无论是多核还是单处理器,volatile关键字都应具有同等的重要性. 原因是volatile,它保证值将在主存储器(堆)中更新而不是保持 它在所有线程都可以看到的线程本地内存(堆栈)中.因此,无论是多核还是单处理器, 它有什么不同?

As per my understanding volatile keyword should have equal importance whether it is multicore vs single processor. Reason is with volatile , its guaranteed that value will be updated in main memory (heap) instead of keeping it in thread local memory(stack) which can be seen by all threads. So whether its multicore or single processor, how does it makes difference?

推荐答案

易失性"与内核数无关. JVM隐藏了基础架构.更不用说volatile是语言关键字,因此它在每种体系结构上的行为都应相同.

The "sense of volatile" has nothing to do with the number of cores. The JVM hides the underlying architecture. Not to mention that volatile is a language keyword, so it should behave the same on every architecture.

您描述了volatile的作用,这是正确的. 应用程序的体系结构,可能需要使用volatile,而无需其他任何操作.

You described what volatile does, and it is correct. The architecture of the application that could require the usage of volatile, nothing else.

如果您有兴趣,这是一篇与volatile有关的好文章,以及Java中使用的内存模型的基本概念.

If you are interested, here is a great post related to volatile, and the basic concepts of the memory model used in Java.

http://jeremymanson.blogspot.hu/2008/11/what-volatile-means-in-java.html

这篇关于多核与单处理器中的易失性关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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