R
Roedy Green
Originally I thought volatile just suppressed caching a value in a
register, so that other threads going to RAM would see the latest
value.
IIRC at least in some early JVM, you could not count on 64-bit loads
and stores being atomic.
But on reading the JLS, it seems to guarantee even more. It says all
threads must see a consistent value.
This suggests if your hardware stores a 64-bit long in two 32-bit
stores, it must somehow lock the pair together so that another thread
will not see half the store. I wonder just how they do that, and if
they indeed do.
I don't think the JLS guarantees that a volatile x++ must be atomic.
It appears to be silent on the topic, which I take to mean you can't
count on it.
Any thoughts?
register, so that other threads going to RAM would see the latest
value.
IIRC at least in some early JVM, you could not count on 64-bit loads
and stores being atomic.
But on reading the JLS, it seems to guarantee even more. It says all
threads must see a consistent value.
This suggests if your hardware stores a 64-bit long in two 32-bit
stores, it must somehow lock the pair together so that another thread
will not see half the store. I wonder just how they do that, and if
they indeed do.
I don't think the JLS guarantees that a volatile x++ must be atomic.
It appears to be silent on the topic, which I take to mean you can't
count on it.
Any thoughts?