Java volatile and cache coherence

感情迁移 提交于 2019-12-03 08:50:54

问题


If cache coherency is implemented at hardware level why do we need volatile? Any core/processor should get the latest value anyway?

Or is it dealing with a different issue completely?


回答1:


Cache coherence may be implemented at the processor level but, unless the processor memory model guarantees sequential consistency (which is not the case on most modern architectures), you will only get cache coherence if you ask for it.

That is what volatile is for: it asks the JVM to produce the relevant machine instruction(s) that will ask the processor(s) to synchronize its cache with main memory.



来源:https://stackoverflow.com/questions/21129018/java-volatile-and-cache-coherence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!