在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System;
using System.Collections.Generic; using System.Text; using System.Threading; namespace @lock { class Program { public static object lock_A = new object(); public static object lock_B = new object(); public void DoSomething() { lock (lock_A) { Thread.Sleep(500); Console.WriteLine("我是lock_A,我想要lock_B"); lock (lock_B) { Console.WriteLine("没出现这句话表示死锁了"); } } } static void Main() { Program a = new Program(); Thread th = new Thread(new ThreadStart(a.DoSomething)); th.Start(); lock (lock_B) { Console.WriteLine("我是lock_B,我想要lock_A"); lock (lock_A) { Console.WriteLine("没出现这句话表示死锁了"); } } Console.WriteLine("没出现这句话表示死锁了"); } } } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论