0 votes
in JAVA by
What guarantee volatile variable provides?

1 Answer

0 votes
by
volatile variables provide the guarantee about ordering and visibility e.g. volatile assignment cannot be re-ordered with other statements but in the absence of any synchronization instruction compiler, JVM or JIT are free to reorder statements for better performance. volatile also provides the happens-before guarantee which ensures changes made in one thread is visible to others. In some cases volatile also provide atomicity e.g. reading 64-bit data types like long and double are not atomic but read of volatile double or long is atomic.

Related questions

+1 vote
asked Jan 24, 2020 in JAVA by rahuljain1
0 votes
asked Feb 15, 2020 in JAVA by rahuljain1
...