码迷,mamicode.com
首页 > 其他好文 > 详细

Volatile variables

时间:2018-01-26 20:50:57      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:prevent   values   safe   word   event   rom   developer   dsa   volatile   

Volatile variables apply another type of memory constraint to individual variables. The compiler often optimizes code by loading the values for variables into registers. For local variables, this is usually not a problem. If the variable is visible from another thread however, such an optimization might prevent the other thread from noticing any changes to it. Applying the volatile keyword to a variable forces the compiler to load that variable from memory each time it is used. You might declare a variable as volatile if its value could be changed at any time by an external source that the compiler may not be able to detect.

 

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html#//apple_ref/doc/uid/10000057i-CH8-124887

Volatile variables

标签:prevent   values   safe   word   event   rom   developer   dsa   volatile   

原文地址:https://www.cnblogs.com/feng9exe/p/8361018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!