Explicit volatility effect for other variables

I am trying to understand the following paragraph about volatile variables in java. (from section 3.1.4 Java concurrency in practice):

"The effects of the visibility of volatile variables extend beyond the value of the volatile variable itself. When thread A writes to a volatile variable and then thread B reads that same variable, the values โ€‹โ€‹of all variables that were visible to A before being written to the volatile variable become visible to B after reading the volatile variable. So, in terms of memory visibility, writing a volatile variable is like exiting a synchronized block, and reading a volatile variable is like entering a synchronized block. "

Why does writing to a volatile variable A and reading the same variable B make other variables visible to B? Is it because volatility acts as a barrier?

+3


source to share





All Articles