codescracker


operating system os

OS Deadlock Prevention



« Previous Tutorial Next Tutorial »


Deadlock avoidance is basically not possible only because it requires information about future requests which isn't known.

If we can ensure that at least one of the four condition for deadlock is never satisfied, then deadlock will be structurally not possible.

Now the table given below describes briefly about all those four conditions for deadlocks (that we have learned/discussed in earlier tutorial) one by one.

Condition Description
Attacking the Mutual Exclusion Condition In case if no resource were ever assigned exclusively to a single process, then we would never have any deadlocks. But allowing two processes to write on the printer at the same instance of time will lead to chaos. By spooling printer output, several process can produce output at the same time. In this model, the only process that actually requests the physical printer is the printer daemon. Since the daemon never requests any other resources, we can eliminate deadlock for the printer.
Attacking the Hold and Wait Condition If we can prevent processes that hold resources from waiting for more resources, we can eliminate deadlocks. A way to achieve this goal is to require all the processes to request all their resources before starting the execution. If everything is available then the process will be allocated whatever it needs and can run to completion. Nothing will be allocated and the process would wait, in case if one or more than one resources are busy
Attacking the No Preemption Condition If a process has been assigned the printer and is in the middle of printing its output, forcibly taking away from the printer because a needed plotter is not available is tricky at best and impossible at worst
Attacking the Circular Wait Condition In several ways, the circular wait can be eliminated. One way is to have a rule saying that a process is entitled only to a single resource at any moment. If it needs a second one then it must release the first one. For a process that needs to copy a huge file from a tape to a printer, this restriction is unacceptable

Now let's summarise the approaches to deadlock presentation.

Approaches to Deadlock Prevention

The table given below summarises the approaches of deadlock prevention.

Condition Approache
Mutual exclusion Spool everything
Hold and wait Request all resources initially
No preemption Take resources away
Circular wait Order resources numerically

« Previous Tutorial Next Tutorial »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test