首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Volatile关键字的功用

2013-03-29 
Volatile关键字的作用It is possible for each thread to have a local?stack and maintain copies of som

Volatile关键字的作用

It is possible for each thread to have a local?

stack and maintain copies of some variables there. If you define a variable as volatile, it tells?

the compiler not to do any optimizations that would remove reads and writes that keep the?

field in exact synchronization with the local data in the threads. In effect, reads and writes go?

directly to memory, and are not cached, volatile also restricts compiler reordering of?

accesses during optimization.

?

Basically, you should make a field volatile if that field could be simultaneously accessed by?

multiple tasks, and at least one of those accesses is a write. For example, a field that is used?

as a flag to stop a task must be declared volatile; otherwise, that flag could be cached in a?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

register, and when you make changes to the flag from outside the task, the cached value?

wouldn’t be changed and the task wouldn’t know it should stop.?

热点排行