Try   HackMD

Deadlock avoidance

Deadlock avoidance

  • 可以利用演算法避免deadlock
  • safe state
    • a save sequence {P1, P2, , Pn}
    • Pi最多可以請求的資源數 = available resources + resources held by all Pj , with j < i
  • unsafe state
    • may lead to a deadlock
      • not all unsafe states are deadlocks

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Ex: P2在t1時多拿了一個資源

Resource-Allocation-Graph Algorithm

  • For one instance of each resource type only

  • A direct edge from Pi → Rj is called a request edge

  • A direct edge from Rj → Pi is called a assignment edge

  • claim edge

    • Pi → Rj 代表 Pi 未來某個時間點可以請求 Rj
    • 虛線表示
    • 當Pi請求Rj,Pi → Rj會轉換成request edge(實線)
    • 當Pi釋放Rj, assignment edge Rj → Pi 會轉換成claim edge
  • Pi 開始執行之前,所有的claim edge都要出現在圖上

  • 如果edge的方向轉換後會造成cycle,就不能讓請求成立

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Banker's Algorithm

  • For multiple instance of each resource type

  • Data structure

    • n = number of processes

    • m = number of resources types

    • Available

      • 長度為 m 的一維陣列
      • Available[j] = k 代表Rj有k個可用資源
    • Max

      • n×m
        的二維陣列
      • Max[i, j] = k 代表Pi最多可以請求 k 個 Rj 資源
    • Allocation

      • n×m
        的二維陣列
      • Allocation[i, j] = k 代表 Pi 已經有 k 個 Rj
    • Need

      • n×m
        的二維陣列
      • Need[i, j] = k 代表 Pi 需要再 k 個 Rj 才能完成任務
    • Need[i, j] = Max[i, j] - Allocation[i, j]

      • Pi 需要的 Rj 資源數 = Pi 最多可以請求的 Rj 數 - Pi 已經有的 Rj

Safety algorithm

  • 用來決定一個特定狀態是不是safe
  1. Initialize

    • Let Work and Finish be vectors of length m and n
    • Work = Available
    • Finish[i] = false, i = 0, 1, , n-1
  2. Find an i

    • Finish[i] = false && Needi ≤ Work
    • 如果i不存在,跳到4
  3. 可以執行

    • Work = Work + Allocation[i] process釋放資源
    • Finish[i] = true 工作完成
    • 回到2
  4. 如果 Finish中全部都是 true,代表系統現在是 safe state

Resource-request algorithm

  • 用來決定一個新的請求是不是safe,如果是safe就讓它執行
  1. If Requesti ≤ Needi go to step 2

    • Requesti不能比Needi大,否則會超過Pi最多可請求的資源數
  2. If Requesti ≤ Availablei go to step 3

    • If not, Pi must wait
  3. Available=AvailableRequestiAllocationi=Allocationi+RequestiNeedi=NeediRequesti

    • 可用資源被該process請求資源扣掉
    • 該process所佔有的資源增加
    • 該process還需要的資源減少
    • 如果結果是safe → 把資源給Pi
    • 如果結果是unsafe → wait

last edit

dotTue, Jul 28, 2020 10:38 PM

HOME PAGE

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

tags: OS CSIE