我们可以使用死锁吗?(Can we use deadlocks for anything?)

编程入门 行业动态 更新时间:2024-10-27 21:19:31
我们可以使用死锁吗?(Can we use deadlocks for anything?)

我想知道这件事。 死锁是我们希望避免的,但是在任何情况下我们都可以使用死锁来获得优势吗?

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.

enter image description here

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.

更多推荐

本文发布于:2023-08-01 08:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1356710.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:死锁   可以使用   deadlocks

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!