如何避免死锁? [英] How to avoid deadlocks?

查看:102
本文介绍了如何避免死锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用多个线程时,共享内存需要由关键部分锁定。但是,使用临界段会导致潜在的死锁。

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?

推荐答案

一种方法是使用关键部分的层次结构。如果您确保父级临界区从未在其子级之一中输入,则死锁不会发生。困难是强制执行这种层次结构。

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.

这篇关于如何避免死锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆