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

Csharp volatile 关键字

时间:2014-07-10 15:44:40      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:http   os   for   io   type   res   

The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times.

The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access.

The volatile keyword can be applied to fields of these types:

  • Reference types.

  • Pointer types (in an unsafe context). Note that although the pointer itself can be volatile, the object that it points to cannot. In other words, you cannot declare a "pointer to volatile."

  • Types such as sbyte, byte, short, ushort, int, uint, char, float, and bool.

  • An enum type with one of the following base types: byte, sbyte, short, ushort, int, or uint.

  • Generic type parameters known to be reference types.

  • IntPtr and UIntPtr.

The volatile keyword can only be applied to fields of a class or struct. Local variables cannot be declared volatile.

 

 

http://msdn.microsoft.com/en-us/library/vstudio/x13ttww7(v=vs.100).aspx

Csharp volatile 关键字,布布扣,bubuko.com

Csharp volatile 关键字

标签:http   os   for   io   type   res   

原文地址:http://www.cnblogs.com/fengye87626/p/3835006.html

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