我想知道这件事。 死锁是我们希望避免的,但是在任何情况下我们都可以使用死锁来获得优势吗?
I was wondering about this. Deadlocks are something we prefer to avoid, but is there any scenario where we can use deadlocks to our advantage?
最满意答案
死锁是指两个或多个竞争行为各自等待另一个完成的情况,因此两者都没有。
所以你的目标是避免陷入其中。 如果您的代码导致死锁,那么您需要返回并重新设计一些代码以避免/最小化此类死锁。 当你遇到死锁时,也可以使用某种恢复和警告机制。
现在问你的问题:这可以用于什么吗? 嗯,总有一个好用的东西取决于你的情况和你的目标。 以下是一些场景:
如果你是一个试图攻击某个应用程序的黑客,你可以通过强制它进入许多死锁来冻结系统。 如果您是某个死锁检测系统的构建者,那么您希望在测试环境中生成此类死锁,以查看它是否会被您的系统捕获。A deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does.
So your goal is to avoid falling into it. If your code result in a deadlock then you need to go back and do some code re-designing to avoid/minimize such deadlocks. Also it might be a good idea to have some kind of recovery & warning mechanism for when you hit a deadlock.
Now for your question: Can this be used for something? Well, there is always a good use for anything depends on your situation and your goal. Here are some scenarios:
If you are a hacker who tries to attack some app, you can freeze the system by forcing it into many deadlocks. If you are a builder of some deadlock detecting system, you want then to generate such deadlocks in your testing environment to see if it will be caught by your system or not.更多推荐
发布评论