Writing long and double is not atomic in Java?

前端 未结 6 1610
甜味超标
甜味超标 2020-12-02 18:37

Reading and writing of a single variable is atomic (language guarantee!), unless the variable is of type long or double.

I was reading

6条回答
  •  天命终不由人
    2020-12-02 19:18

    Java programming language memory model, a single write to a non-volatile long or double value is treated as two separate writes: one to each 32-bit half. This can result in a situation where a thread sees the first 32 bits of a 64-bit value from one write, and the second 32 bits from another write.

提交回复
热议问题