int
is 32 bits and long
/double
are 64 bits. Will these sizes remain same on long
/double
be atomic on a 64 bit processor/JVM?The Oracle Java tutorial says:
Reads and writes are atomic for reference variables and for most primitive variables (all types except long and double).
Does this statement has anything to do with jvm/processor architecture? Can someone please explain.
3. Finally will i be able to make read/write of double/long atomic if i use 64 bit jvm and processor
Yes, the sizes are the same on both 32-bit and 64-bit JVM. Assignment is not guaranteed to be atomic for either long or double in Java. Atomic assignment, is still no guarantee of visibility from another thread. Because threads are allowed to 'shadow' variables in memory, even atomic assignment to a variable does not necessarily write-thru to main memory (but when main memory is updated, it will be done so atomically). You must always use synchronization barriers of some kind when accessing shared state from two or more threads if you expect one thread to consistently see changes by the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With