How to explain the “deadlock” better?

前端 未结 15 1034
不知归路
不知归路 2020-12-13 00:52

I am struggling to explain \"deadlock\" in threads in easy words, so please help. What could be the best example of \"deadlock\" (say, in Java), and how it does happen in st

15条回答
  •  余生分开走
    2020-12-13 01:25

    Imagine a criminal holding a hostage and asking for a ransom. You show up with a suitcase full of money.

    The criminal will never release the hostage before he gets the money. You will never release the money before you get the hostage. Deadlock.


    The analogy here are:

    • You and the criminal are the threads
    • The suitcase full of money and the hostage are the resources

提交回复
热议问题