• edited by
21,057 views
51 51 votes

Consider the following policies for preventing deadlock in a system with mutually exclusive resources.

  1. Process should acquire all their resources at the beginning of execution. If any resource is not available, all resources acquired so far are released.
  2. The resources are numbered uniquely, and processes are allowed to request for resources only in increasing resource numbers
  3. The resources are numbered uniquely, and processes are allowed to request for resources only in deccreasing resource numbers
  4. The resources are numbered uniquely. A processes is allowed to request for resources only for a resource with resource number larger than its currently held resources

Which of the above policies can be used for preventing deadlock?

  1. Any one of (I) and (III) but not (II) or (IV)
  2. Any one of (I), (III) and (IV) but not (II)
  3. Any one of (II) and (III) but not (I) or (IV)
  4. Any one of (I), (II), (III) and (IV)

5 Answers

Best answer
98 98 votes

A deadlock will not occur if any one of the below four conditions are prevented:

  1. hold and wait
  2. mutual exclusion
  3. circular wait
  4. no-preemption

Now,

Option-$1$ if implemented violates $1$ so deadlock cannot occur.

Option-$2$ if implemented violates circular wait (making the dependency graph acyclic)

Option-$3$ if implemented violates circular wait (making the dependency graph acyclic)

Option-$4$ it is equivalent to options $2$ and $3$

So, the correct option is $4$ as all of them are methods to prevent deadlock.

http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/7_Deadlocks.html

• edited by
12 12 votes
Answer is D These all cases are various methods for preventing deadlock
6 6 votes
As mentioned in the question, these are all techniques of preventing a Deadlock prevention as mentioned in the question. Please note the term Lock and Resources are used interchangeably.

Setting, 10 resources in the system 1, 2, 3, 4.. 10 and all the threads in the system needs all the resources.

1. In this case, the thread start acquiring the lock in random order and if it fails then it retries again. Here CPU cycles are wasted as it might be the case that one thread as acquired the the locks till 9 and then some other thread starts acquiring lock from 10. In this case the earlier thread which was almost done has to retry again and all the work done for acquiring 9 locks is wasted.

2. In this case the thread follows patter that it starts acquiring lock in increasing order. Here if a thread gets lock on resource 1, then it is sure to get all the locks ( This requires a condition of releasing order. Food for thought?).

3.This is same as case 2 here it start acquiring lock in decreasing order. Increasing or decreasing does not matter till all the threads follow some pattern. This will reduce wasted work ( might not even allow thread to do wasteful work).

4. This case is interesting. In current setting this is same as option 2 because every thread will start from Resource 1. This will be different when the requirements of each thread is not same. Here then it is not guaranteed that if you acquire Resource/Lock 1, you will succeed in acquiring everything. For example, suppose thread A need 1,2,3,4,5 and thread B needs 4,5,6,7,8 so when thread A and B starts, thread A will fail at lock 5 (assuming both get a chance to run and other scheduling operations are same).

Hope this helps.
4 4 votes
As option I is a standard method to avoid deadlock which overcomes hold and wait one of the four conditions for deadlock.

II and III and IV can be used to avoid condition of circular wait.

so answer is option D
0 0 votes
A deadlock will never take place if any one of the following condition is preempted.

1. Hold & Wait

2. Circular Wait

3. Mutual Exclusion

4. No-Preemption

           Statement I    violates hold & wait.

           Statement II  violates circular wait.

           Statement III  violates circular wait.

           Statement IV also violates circualr wait by making dependency graph acyclic.

Therefore, option D is correct
ago
Answer:
Position:
Show:

Related questions

67 67 votes
8 answers 8 answers
33.3k
33.3k views
go_editor asked Feb 15, 2015
33,317 views
For the processes listed in the following table, which of the following scheduling schemes will give the lowest average turnaround time?$$\small \begin{array}{|c|c|c|} \h...
104 104 votes
7 answers 7 answers
39.8k
39.8k views
go_editor asked Feb 14, 2015
39,782 views
Two processes $X$ and $Y$ need to access a critical section. Consider the following synchronization construct used by both the processes$$\begin{array}{|l|l|}\hline \text...
8 8 votes
4 answers 4 answers
8.4k
8.4k views
go_editor asked Feb 16, 2015
8,396 views
Consider the following software items: Program-$X$, Control Flow Diagram of Program-$Y$ and Control Flow Diagram of Program-$Z$ as shown belowThe values of McCabe's Cyclo...
68 68 votes
5 answers 5 answers
20.8k
20.8k views
go_editor asked Feb 16, 2015
20,814 views
Consider the following C program:#include<stdio.h int f1(void); int f2(void); int f3(void); int x=10; int main() { int x=1; x += f1() + f2 () + f3() + f2(); printf("%d", ...