c#死锁示例代码

void Main()
{
object obj1 = new object();
object obj2 = new object(); var t1 = new Thread(delegate(object p)
{
lock(obj1)
{
Thread.Sleep();
lock(obj2)
{
Console.WriteLine("Thread1 executed.");
}
}
}); t1.Start(); var t2 = new Thread(delegate(object p)
{
lock(obj2)
{
Thread.Sleep();
lock(obj1)
{
Console.WriteLine("Thread2 executed.");
}
}
}); t2.Start(); t1.Join();
t2.Join(); Console.WriteLine("over");
}
上一篇:设置windows10 背景颜色


下一篇:Ramnit 蠕虫分析