IAE Academy

GATE 2018 CS Q.39: solution and answer

GATE 2018 · CSQ.39 · 2 marks · MCQ

In a system, there are three types of resources: , and . Four processes and execute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, is the maximum number of instances of that would require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation.

Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of and 3 instances of are the only resources available.

Allocation:

Max:

From the perspective of deadlock avoidance, which one of the following is true?

GATE 2018 CS question 39: Two side-by-side 4x3 tables.Tap to open full size
Figure from the GATE 2018 CS paper. It is part of the question.
Figure description

Two side-by-side 4x3 tables. Allocation (columns E, F, G): P0 = 1,0,1; P1 = 1,1,2; P2 = 1,0,3; P3 = 2,0,0. Max (columns E, F, G): P0 = 4,3,1; P1 = 2,1,4; P2 = 1,3,3; P3 = 5,4,1.

  1. (A)

    The system is in safe state.

  2. (B)

    The system is not in safe state, but would be safe if one more instance of were available

  3. (C)

    The system is not in safe state, but would be safe if one more instance of were available

  4. (D)

    The system is not in safe state, but would be safe if one more instance of were available

Answer and solution

ANSWER

The system is in a safe state, with safe sequence . Option (A).

Official answer: ASource: Official answer key, GATE 2018 CS (IIT Guwahati)

  1. The question says only 3 instances of and 3 instances of are available, so the available vector is .

  2. Need Max Allocation:

  3. Banker's safety check, starting with . needs , so it can finish. Then .

  4. needs , but only 1 instance of is free, so it must wait. needs , so it finishes. Then .

  5. Now needs and finishes. Then .

  6. needs and finishes. Then .

  7. The safe sequence exists, so the state is safe. Option (A) is true. Options (B), (C) and (D) each say the state is not safe, so they are false.

KEY IDEA

Deadlock avoidance with the Banker's algorithm. Compute Need Max Allocation, then repeatedly pick any process whose Need is at most Work, let it finish and add its Allocation back. If every process can finish, the state is safe.

WATCH OUT FOR

Forgetting that no instance of is free, and treating Available as or reading the allocations as the available amounts. Another slip is starting with , whose need of 2 instances of cannot be met until releases its resources.

From the GATE 2018 CS paper. Every question of this paper · Download the full paper · All 6 Deadlock questions, with notes

More Deadlock questions