So I am reading this book titled Java Concurrency in Practice and I am stuck on this one explanation which I cannot seem to comprehend without an example. This is the quote:
When thread A
writes to a volatile
variable and subsequently thread B
reads that same variable, the values
of all variables that were visible to
A
prior to writing to the volatile
variable become visible to B
after
reading the volatile variable.
Can someone give me a counterexample of why "the values of ALL variables that were visible to A
prior to writing to the volatile variable become visible to B
AFTER reading the volatile variable"?
I am confused why all other non-volatile variables do not become visible to B
before reading the volatile variable?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…