multithreading - Volatile variable in Java -



multithreading - Volatile variable in Java -

so reading book titled java concurrency in practice , stuck on 1 explanation cannot seem comprehend without example. quote:

when thread a writes volatile variable , subsequently thread b reads same variable, values of variables visible a prior writing volatile variable become visible b after reading volatile variable.

can give me counterexample of why "the values of variables visible a prior writing volatile variable become visible b after reading volatile variable"?

i confused why other non-volatile variables not become visible b before reading volatile variable?

thread b may have cpu-local cache of variables. read of volatile variable ensures intermediate cache flush previous write volatile observed.

for example, read next link, concludes "fixing double-checked locking using volatile":

http://www.cs.umd.edu/~pugh/java/memorymodel/doublecheckedlocking.html

java multithreading concurrency volatile

Comments

Popular posts from this blog

Php operator `break` doesn't stop while -

ubuntu - Bash Script to Check That Files Are Being Created -

vim: Search & replace -