1

I am a beginner in Multi Threading and came across this concept of Volatile variable whose one of the definitions is:

It ensures that every read/write is done from/to main memory

What I want to understand is that are these variables not stored in cache at all and only in main memory or are there modifications etc are directly written to main memory and completely skip the cache?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
ghostrider
  • 2,046
  • 3
  • 23
  • 46
  • 1
    The Java language spec only prescribes what will be visible to programs running on the JVM. How this is going to be implemented by specific JVM versions and underlying hardware is up to those. FWIW, on modern CPU all memory access (reads and writes) has to go through the on-CPU cache I think. – Thilo Mar 19 '19 at 13:11
  • @Thilo You can define memory region as non cachable but in practice this is only done for the purpose of accessing memory mapped peripherals. Also this might require supervisor privilege. – curiousguy Mar 19 '19 at 22:14

0 Answers0