737 views
0 votes
0 votes
One way to prevent deadlocks is to eliminate the hold-and-wait condition. In the text it was proposed that before asking for a new resource, a process must first release whatever resources it already holds (assuming that is possible). However, doing so introduces the danger that it may get the new resource but lose some of the existing ones to competing processes. Propose an improvement to this scheme.

2 Answers

0 votes
0 votes
Assuming that preemption is possible, (its default as question itself assumes it).

Problem with given algorithm: Requesting process may lose what it already has. This may lead to it never getting all resources it may need. So we have to think of a way to stop this.

New Algorithm: When we request new resource if it can be available and can be given to it then it will get it and no one can get what resources it already previously has.

Is deadlock possible? No. Also there is no danger that the new resource is acquired but existing ones lost.

Other way: (not answer to this question as its asking for improvement of given scheme and not new scheme)

A resource can get all required resources before it start execution. This will avoid deadlock, but will result in reduced throughputs as resources are held by processes even when they are not needed. They could have been used by other processes during this time.
0 votes
0 votes
One improvement can be to release only those resources which form a cycle (and hence a deadlock) at the moment. In that way, the probability of losing resources it already held can be reduced.

Related questions

0 votes
0 votes
1 answer
3