在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
void Main() { object obj1 = new object(); object obj2 = new object(); var t1 = new Thread(delegate(object p) { lock(obj1) { Thread.Sleep(5000); lock(obj2) { Console.WriteLine("Thread1 executed."); } } }); t1.Start(); var t2 = new Thread(delegate(object p) { lock(obj2) { Thread.Sleep(5000); lock(obj1) { Console.WriteLine("Thread2 executed."); } } }); t2.Start(); t1.Join(); t2.Join(); Console.WriteLine("over"); }
|
请发表评论