日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Csharp volatile 关键字

發布時間:2025/6/17 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Csharp volatile 关键字 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

volatile 關鍵字指示一個字段可以由多個同時執行的線程修改。聲明為 volatile 的字段不受編譯器優化(假定由單個線程訪問)的限制。這樣可以確保該字段在任何時間呈現的都是最新的值。

volatile 修飾符通常用于由多個線程訪問但不使用 lock 語句對訪問進行序列化的字段。

volatile 關鍵字可應用于以下類型的字段:

  • 引用類型。

  • 指針類型(在不安全的上下文中)。請注意,雖然指針本身可以是可變的,但是它指向的對象不能是可變的。換句話說,您無法聲明“指向可變對象的指針”。

  • 整型,如 sbyte、byte、short、ushort、int、uint、char、float 和 bool。

  • 具有整數基類型的枚舉類型。

  • 已知為引用類型的泛型類型參數。

  • IntPtr 和 UIntPtr。

?

?

?

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

轉載于:https://www.cnblogs.com/fengye87626/p/3835006.html

總結

以上是生活随笔為你收集整理的Csharp volatile 关键字的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。