Is writing a reference atomic on 64bit VMs
Posted
by Steffen Heil
on Stack Overflow
See other posts from Stack Overflow
or by Steffen Heil
Published on 2010-04-05T01:18:06Z
Indexed on
2010/04/05
1:23 UTC
Read the original article
Hit count: 436
Hi
The java memory model mandates that writing a int
is atomic: That is, if you write a value to it (consisting of 4 bytes) in one thread and read it in another, you will get all bytes or none, but never 2 new bytes and 2 old bytes or such.
This is not guaranteed for long
. Here, writing 0x1122334455667788
to a variable holding 0
before could result in another thread reading 0x112233440000000
or 0x0000000055667788
.
Now the specification does not mandate object references to be either int or long-sized. For type safety reasons I suspect they are guaranteed to be written atomiacally, but on a 64bit VM these references could be very well 64bit values (merely memory addresses).
No here are my question:
- Are there any memory model specs covering this (that I haven't found)?
- Are long-writes suspect to be atomic on 64bit VMs?
- Are VMs forced to map references to 32bit?
Regards, Steffen
© Stack Overflow or respective owner