How to avoid deadlocks?

前端 未结 8 882
隐瞒了意图╮
隐瞒了意图╮ 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:40

    When I work in C++, the following works for me:

    1. all public methods (excluding ctor and dtor) of a threadsafe class lock

    2. private methods cannot call public methods

    It's not a general deadlock avoidance method.

提交回复
热议问题