Line 1: Line 1:
 
A system has <math>n</math> resources <math>R_0 ,..., R_n-1</math> , and <math>k</math> processes <math>P_0 ,.....P_{k-1}</math> . The implementation of the resource
 
A system has <math>n</math> resources <math>R_0 ,..., R_n-1</math> , and <math>k</math> processes <math>P_0 ,.....P_{k-1}</math> . The implementation of the resource
 
request logic of each process <math>P_i</math> . is as follows:
 
request logic of each process <math>P_i</math> . is as follows:
<math>
+
 
if (i% 2==0) {
+
if (<math>i% 2==0</math>) {
   if (i<n) request Ri ;
+
   if (<math>i<n</math>) request <math>R_i</math> ;
   if (i+2<n)request Ri+2 ;
+
   if (<math>i+2<n</math>)request <math>R_{i+2}</math> ;
 
}
 
}
 
else {
 
else {
   if (i<n) request Rn-i ;
+
   if (<math>i<n</math>) request <math>R_{n-i}</math> ;
   if (i+2<n) request Rn-i-2 ;
+
   if (<math>i+2<n</math>) request <math>R_{n-i-2}</math> ;
 
}
 
}
</math>
+
 
  
 
In which one of the following situations is a deadlock possible?
 
In which one of the following situations is a deadlock possible?

Revision as of 12:56, 11 December 2013

A system has <math>n</math> resources <math>R_0 ,..., R_n-1</math> , and <math>k</math> processes <math>P_0 ,.....P_{k-1}</math> . The implementation of the resource request logic of each process <math>P_i</math> . is as follows:

if (<math>i% 2==0</math>) {

 if (<math>i<n</math>) request <math>R_i</math> ;
 if (<math>i+2<n</math>)request <math>R_{i+2}</math> ;

} else {

 if (<math>i<n</math>) request <math>R_{n-i}</math> ;
 if (<math>i+2<n</math>) request <math>R_{n-i-2}</math> ;

}


In which one of the following situations is a deadlock possible?

(A) n = 40,k = 26

(B) n = 21,k = 12

(C) n = 20,k = 10

(D) n = 41,k = 19

Solution

From the resource allocation logic, it's clear that even numbered processes are taking even numbered resources and all even numbered resources are taken by 2 processes. Now, if we make sure that all odd numbered processes take odd numbered resources, then dead lock cannot occur. The "else" case of the resource allocation logic, is trying to do that. But, if n is odd, Rn-i and Rn-i-2 will be even and there is possibility of deadlock.





blog comments powered by Disqus

A system has <math>n</math> resources <math>R_0 ,..., R_n-1</math> , and <math>k</math> processes <math>P_0 ,.....P_{k-1}</math> . The implementation of the resource request logic of each process <math>P_i</math> . is as follows: <math> if (i% 2==0) {

 if (i<n) request Ri ;
 if (i+2<n)request Ri+2 ;

} else {

 if (i<n) request Rn-i ;
 if (i+2<n) request Rn-i-2 ;

} </math>

In which one of the following situations is a deadlock possible?

(A) n = 40,k = 26

(B) n = 21,k = 12

(C) n = 20,k = 10

(D) n = 41,k = 19

Solution[edit]

From the resource allocation logic, it's clear that even numbered processes are taking even numbered resources and all even numbered resources are taken by 2 processes. Now, if we make sure that all odd numbered processes take odd numbered resources, then dead lock cannot occur. The "else" case of the resource allocation logic, is trying to do that. But, if n is odd, Rn-i and Rn-i-2 will be even and there is possibility of deadlock.





blog comments powered by Disqus