Locking strategies and techniques for preventing deadlocks in code

后端 未结 5 1113
执笔经年
执笔经年 2020-12-04 10:14

The common solution to preventing deadlock in code is to make sure the sequence of locking occur in a common manner regardless of which thread is accessing the resources.

5条回答
  •  [愿得一人]
    2020-12-04 10:41

    Another technique is transactional programming. This though is not very common as it usually involves specialized hardware (most of it currently only in research institutions).

    Each resource keeps track of modifications from different threads. The first thread to commit changes to all resources (it is using) wins all other thread (using those resources) get rolled back to try again with the resources in the new committed state.

    A simplistic starting point for reading on the subject is transactional memory.

提交回复
热议问题