Casey
Casey

Reputation: 10946

Trouble implementing a deadlock detection algorithm

I've got it all sorted out except for one specific confusion regarding:

if Allocationi != 0, then Finish[i] := false; otherwise, Finish[i] := true.

Does this mean the sum of that particular row is zero or what?

Algorithm:

Data Structures:

Algorithm:

  1. Initialize Work := Available.
    • For i = 1, 2, …, n, if Allocationi != 0, then Finish[i] := false; otherwise, Finish[i] := true.
  2. Find an index i such that both:
    • (a) Finish[i] = false
    • (b) Requesti <= Work
    • if no such i exists, go to step 4.
  3. Work := Work + Allocationi
    • Finish[i] := true
    • go to step 2
  4. If Finish[i] = false, for some i, 1 <= i...n, then the system is in a deadlock state. Moreover, if Finish[i] = false, then process Pi is deadlocked. The less-than-or-equal relation (<=) between two vectors is defined as follows: let X and Y be vectors of length n. We say that X <= Y if and only if x[i] <= y[i] for all i = 1, 2, ..., n. The rows of the Allocation and Request matrices are treated as vectors and are referred to as Allocationi and Requesti in the algorithm.

Upvotes: 1

Views: 474

Answers (1)

nneonneo
nneonneo

Reputation: 179552

Since Allocationi is a vector, "Allocationi != 0" means to test Allocationi against the zero vector (the vector consisting of all zeros).

In other words, "Allocationi == 0" iff every entry in the vector is 0.

Upvotes: 1

Related Questions