Java memory model - can someone explain it?

前端 未结 9 1727
一个人的身影
一个人的身影 2020-11-30 01:38

For years and years, I\'ve tried to understand the part of Java specification that deals with memory model and concurrency. I have to admit that I\'ve failed miserably. Yes\

9条回答
  •  粉色の甜心
    2020-11-30 01:58

    • non-volatile variables can be cached thread-locally, so different threads may see different values at the same time; volatile prevents this (source)
    • writes to variables of 32 bits or smaller are guaranteed to be atomic (implied here); not so for long and double, though 64bit JVMs probably implement them as atomic operations

提交回复
热议问题