volatile qualifier
system reads value from the temporary register to make a program fast(optimization turned on or multiple threads write a shared value), hence if a value is changed frequently then compiler becomes unable to predict it's value and it gives old value instead of updated one.
volatile qualifier tells system to read value directly from memory every time, so it always gives the updated value. Always use volatile qualifier when
1. multiple threads share same object or variable
2 . program optimization is turned on.
volatile qualifier tells system to read value directly from memory every time, so it always gives the updated value. Always use volatile qualifier when
1. multiple threads share same object or variable
2 . program optimization is turned on.
0 comments: