volatile qualifier

Tuesday, December 20, 2016 Unknown 0 Comments

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. 


0 comments: