How to avoid deadlocks?

前端 未结 8 953
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 03:30

When using multiple threads, shared memory needs to be locked by critical sections. However, using critical sections causes potential deadlocks. How can they be avoided?

8条回答
  •  终归单人心
    2021-02-01 03:57

    One way is to use a hierarchy of critical sections. If you ensure that a parent critical section is never entered within one of its children, deadlocks cannot happen. The difficulty is to enforce this hierarchy.

提交回复
热议问题