zoukankan      html  css  js  c++  java
  • C# volatile 的使用

    class Program
    {
      private static volatile bool bChanged;
      static void Main(string[] args)
      {
        Thread t1 = new Thread(run1);
        Thread t2 = new Thread(run2);
        t1.Start();
        t2.Start();
        Console.Read();
      }
      public static void run1()
      {
        for (; ; )
        {
          if (bChanged == !bChanged)
          {
            Console.WriteLine("!=");
            // System.exit(0);
          }
        }
       }


      public static void run2()
      {
        for (; ; )
        {
          bChanged = !bChanged;
        }
      }
    }

  • 相关阅读:
    Linux
    CUDA开发
    Linux C++
    Python
    C++
    模式识别
    Linux
    算法
    算法
    leetcode 数组,链表,跳表
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14213831.html
Copyright © 2011-2022 走看看