Why is reference assignment atomic in Java?

前端 未结 3 1377
太阳男子
太阳男子 2021-02-05 14:09

As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn\'t use atomic pointers internally to model this, since otherwise there would be no n

3条回答
  •  暖寄归人
    2021-02-05 14:38

    Atomic reference assignment is in the specs.

    Writes to and reads of references are always atomic, regardless of whether they are implemented as 32 or 64 bit values.

    Quoted from JSR-133: Java(TM) Memory Model and Thread Specification, section 12 Non-atomic Treatment of double and long, http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf.

提交回复
热议问题