Deep understanding of volatile-[original sky] and deep understanding of volatile
All volatile variables are defined on the memory, for example: int I = 10; int j = I; int k = I; I = 10; is the initialization variable, it is stored in the data segment, and uninitialized variables are stored in the bss segment, that is, when I is left, it is stored in the memory j = I. At this time, I is the right value, so the value of I is in the register, j. The value above the register may change the value in the register during compilation due to compiler reasons, then the value obtained by k is not what we want. If volatile int k = I is added, k takes the value from the memory every time, ensuring the correctness of the value.
Sina Blog: http://blog.sina.com.cn/u/2049150530
Csdn blog: http://blog.csdn.net/u011749143
Blog: http://www.cnblogs.com/sky-heaven/
Sina Weibo: Zhang xiaohua -- sky
Know: http://www.zhihu.com/people/zhang-bing-hua