Chapter 8 Deadlock

  1. Each process utilizes a resource as follow
    1. Request
    2. Use
    3. Release
  2. 死锁示例
  3. 死锁的原因
    • 竞争资源引起死锁
    • 进程推进顺序不当引起死锁
  4. Deadlock characteristics
    • Mutual exclusion
    • Hold and wait
    • No preemption
    • Circular wait
  5. Resource-allocation graph: a set of vertices V and a set of edges E
    • V is partitioned into two types:(V被分为两个部分)
      • P = {P1, P2, …, Pn}, the set consisting of all the processes in the system.(P:含有系统中全部的进程)
      • R = {R1, R2, …, Rm}, the set consisting of all resource types in the system.(R:含有系统中全部的资源)
    • request edge – directed edge Pi  -----> Rj(请求边:直接Pi -----> Rj
    • assignment edge – directed edge Rj  -----> Pi 分配边: Rj  -----> Pi
    • Basic facts
      • If graph contains no cycles -----> no deadlock.
      • If graph contains a cycle
        • If only one instance per resource type, then deadlock.
        • If several instances per resource type, possibility of deadlock.
  6. Methods for handling deadlocks
    • 忽略
      • 鸵鸟策略
      • 大多数用户宁可在极偶然的情况下发生死锁,也不愿限制每个用户只能创建一个进程、只能打开一个文件等等
      • 于是不得不在方便性和正确性之间作出折衷
    • 预防
      • Restrain the ways request can be made
      • 对死锁发生的每一个特征的预防
        • Mutual exclusion
          • Not required for sharable resources; must hold for nonsharable resources
        • Hold and wait
          • Must guarantee that whenever a process requests a resource, it does not hold any other resources
            • Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none
          • 没有资源时,可以申请资源。在申请更多其他资源之前,需要释放已有资源
          • Low resource utilization; starvation possible
        • No preemption
          • If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released
        • Circular wait
          • 所有进程对资源的请求必须严格按照资源序号递增的次序提出
          • 总有一个进程占据了较高序号的资源,它继续请求的资源必然是空闲的,可以一直向前推进
          • 在资源分配图中不可能出现环路,因而摒弃了“环路等待”条件
          • 折衷策略可以提高资源利用率,但在进程使用各类资源的顺序与系统规定的顺序不同时会造成资源浪费的情况
    • 避免
      • 允许进程动态地申请资源,系统在进行资源分配值卡先计算资源分配的安全性
      • Resource-allocation graph algorithm: single instance of a resource type
        • Claim edge Pi  -----> Rj indicated that process Pmay request resource Rj; represented by a dashed line.
        • Claim edge converts to request edge when a process requests a resource.
        • When a resource is released by a process, assignment edge reconverts to a claim edge.
        • Resources must be claimed a priori in the system.
        • 当一个进程Pi 申请资源Rj时,由循环检测算法来检查:
          • 如果把图中的申请边Pi -----> Rj转为分配边Rj -----> Pi ,图中是否会出现环路,只有不出现环路,才实施资源分配。
      • Banker's algorithm: multiple instances of a resource type
        • Each process must a priori claim maximum use.
        • When a process requests a resource it may have to wait. 
        • When a process gets all its resources it must return them in a finite amount of time.
    • 检测: allow system to enter deadlock state
      • Detection algorithm
      • Single instance of each resource type
      • Several instances of a resource type
      • Detection algorithm
    • 解除
      • Process termination
        • Abort all deadlocked processes
        • Abort one process at a time until the deadlock cycle is eliminated
        • In which order should we choose to abort
          • Priority of the process
          • How long process has computed, and how much longer to completion
          • Resources the process has used
          • Resources process needs to complete
          • How many processes will need to be terminated
          • Is process interactive or batch
      • Resource preemption
        • Selecting a victim --- minimum cost
        • Rollback --- return to some safe state, restart process fro that state
        • Starvation --- the same process may always be picked as victim, including number of rollback in cost factor
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值