死锁
2021/9/17 23:09:59
本文主要是介绍死锁,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
static readonly myLock keyA = new myLock("A");
static readonly myLock keyB = new myLock("B");
static void Main(string[] args)
{
Task.Run(() => {
lock (keyA)
{
Console.WriteLine("线程:"+Thread.CurrentThread.ManagedThreadId.ToString() + "进来房间:A");
// Thread.Sleep(2000);
lock (keyB)
{
Console.WriteLine("线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "进来房间:B," + keyB.str);
}
}
});
Task.Run(() =>
{
lock (keyB)
{
Console.WriteLine("线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "进来房间:B,拿着钥匙" + keyB.str);
//Thread.Sleep(3000);
lock (keyA)
{
Console.WriteLine("线程:" + Thread.CurrentThread.ManagedThreadId.ToString() + "进来房间:A," + keyB.str);
}
}
});
这篇关于死锁的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27MQ底层原理资料详解:新手入门教程
- 2024-11-27MQ项目开发资料入门教程
- 2024-11-27RocketMQ源码资料详解:新手入门教程
- 2024-11-27本地多文件上传简易教程
- 2024-11-26消息中间件源码剖析教程
- 2024-11-26JAVA语音识别项目资料的收集与应用
- 2024-11-26Java语音识别项目资料:入门级教程与实战指南
- 2024-11-26SpringAI:Java 开发的智能新利器
- 2024-11-26Java云原生资料:新手入门教程与实战指南
- 2024-11-26JAVA云原生资料入门教程