How to explain the “deadlock” better?

前端 未结 15 1022
不知归路
不知归路 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:06

    Guffa's description is good.

    The best way I've found to avoid deadlocks is to only lock around resources that are private to you, and to release the lock before you call anything that you do not have exclusive control over.

    The only problem is that this may require you to shift from using locks for maintaing consistency to using compensating actions, but it's probably less likely to cause problems in the long run, anyway.

    This article is good to read about this problem.

提交回复
热议问题