edited by
12,500 views
40 votes
40 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)
edited by

4 Answers

Best answer
77 votes
77 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
11 votes
11 votes
Answer is D These all cases are various methods for preventing deadlock
4 votes
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
4 votes
4 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.
Answer:

Related questions

42 votes
42 votes
5 answers
1
69 votes
69 votes
6 answers
2
go_editor asked Feb 14, 2015
20,369 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...
35 votes
35 votes
6 answers
3
go_editor asked Feb 14, 2015
30,234 views
The maximum number of processes that can be in $\textit{Ready}$ state for a computer system with $n$ CPUs is :$n$$n^2$$2^n$Independent of $n$