zoukankan      html  css  js  c++  java
  • string 线程安全


    线程安全:
    class
    Program { public delegate void MyDelegate(string aa); static void Main(string[] args) { MyDelegate dele = new MyDelegate(LockTest); MyDelegate dele1 = new MyDelegate(LockTest); dele.BeginInvoke("aa", null,null); dele1.BeginInvoke("aa", null, null); Console.ReadKey(); } private static void LockTest(string aa) { string thisServiceLock = string.Intern(aa+"_lockCheck"); lock (thisServiceLock) { Console.WriteLine("线程ID" + Thread.CurrentThread.ManagedThreadId.ToString()); Thread.Sleep(10000); Console.WriteLine("线程ID" + Thread.CurrentThread.ManagedThreadId.ToString()); } } }

    线程不安全:

    线程不安全:

     线程不安全;

    线程安全:

    线程不安全:

    线程安全:

     线程安全:

     线程安全:

    线程安全:

    线程不安全:

    线程安全:

    线程不安全:

    原理:https://blog.csdn.net/soonfly/article/details/70147205

    https://www.jianshu.com/p/af6eb8d3d4bf

  • 相关阅读:
    《POJ-2369》
    《1402
    《2018 Multi-University Training Contest 8》
    《HDU
    循环串
    模拟赛 数根 题解
    备份
    关于带删除线性基
    论OIer谈恋爱的必要性
    某计数题题解
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/9445231.html
Copyright © 2011-2022 走看看