fmsf fmsf - 1 year ago 84
Java Question

Writing long and double is not atomic?

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

I was reading a course's slides and I found that written. The class was about concurrency.

Can anyone explain to me why writing a long or a double is not an atomic operation? It really took me by surprise.

Answer Source

It's not atomic because it's a multiple-step operation at the machine code level. That is, longs and doubles are longer than the processor's word length.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download