Q130: Resource allocation graphs and deadlock detection

Question #130: Consider the following resource allocation graphs. Here resources have multiple instances indicated by the circles (R2 has 2 instances, R3 has 1 instance).

Figure 1:

resource_allocation_1

Figure 2:

resource_allocation_2

Which of the following statements is true about the figures above?

Options:

  1. Both depict a deadlock.
  2. Only figure 1 has a deadlock, figure 2 doesn’t.
  3. Only figure 2 has a deadlock, figure 1 doesn’t.
  4. Can’t say.

Solution: 2nd option is the correct one. In figure 1, P1 is waiting for P2, P2 is waiting for P3, P3 is waiting on both P1 & P2 (as can be seen by the cycle). In figure 2, P2 is not waiting for any other process & thus will release R1 eventually, which will break the cycle in the graph and thus it is not deadlocked. This is an example of resource allocation graph with cycle but no deadlock.

Q119: Plotting processes II

This question is in continuation of question #117.

Question #119: What is true for rectangle I1 I2 I5 I6?

Options:

  1. System can never enter this state.
  2. System can enter this state but there will eventually be a deadlock.
  3. This is a deadlock state.
  4. System can enter into this state and can eventually reach ‘u’ (finish the job).

Solution: The correct answer is 2nd one. Once the system enters this state, it means that A has acquired printer and B has acquired plotter. Now after some time, A needs plotter and B needs printer, hence there will be a deadlock in the system.

Q113: Deadlock while acquiring resources

Question #113: Can there be a deadlock in the following piece of code?


semaphore resource_1;

semaphore resource_2;

void process_A(void) {

  down(&resource_1);

  down(&resource_2);

  use_both_resources( );

  up(&resource_2);

  up(&resource_ 1);

}
void process_B(void) {

  down(&resource_1);

  down(&resource_2);

  use_both_resources( );

  up{&resource_2);

  up(&resaurce_1);

}
  1. Yes, process A and process B can both try to acquire resource_1.
  2. No, it is a deadlock free code.
  3. Yes, there can be a deadlock while releasing resources.
  4. None of the above.

Solution: The correct answer is option 2. Any process who acquired the resource_1 first will proceed with the critical section and then the other process will proceed as soon as it releases resource_1.