Are 64 bit assignments in Java atomic on a 32 bit machine?

前端 未结 4 962
轮回少年
轮回少年 2020-12-02 16:12

If I have code like this -

long x;
x  = 0xFFFFFFFFL;


If i run this code on a 32 bit machine is it guaranteed to be atomic or is it po

4条回答
  •  感情败类
    2020-12-02 16:41

    No they are not. A 64 bit store is treated as two separate 32 bit stores. So in a concurrent environment that variable can have the high 32 of one write and the low 32 of another write, obviously not thread safe.

提交回复
热议问题