zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    1.Oracle12cR1的集群件及其组件
    28.oracle监听开启trace file
    connection strings for sql server 2005
    MDAC(Introduce to Microsoft Data Access Components)
    动态链接导入库与静态链接库
    vue3.0小印象
    vue3.0中的vite如何引入markdown文件为页面
    算法
    适配器模式(转载)
    WEB即时通讯之 XMPP OPENFIRE strophe JAXL
  • 原文地址:https://www.cnblogs.com/fengye87626/p/3835006.html
Copyright © 2011-2022 走看看