FANDOM


Introduction Edit

A deadlock is a state that a set of processes can encounter when dealing with resources. A deadlocked system will usually hang and no processes will continue computation. A deadlocked state is one in which the processes are powerless to resolve and require intervention from the operating system.

Resources Edit

Resources are elements in a computing system that a CPU will call upon for information or a service. There are pre-emptiable resources which can be taken away from processes with out ill-effects, ie temp sensor. and non-pre-emptiable resources which can not be commendeared with out the process failing, ie printers.

To acquire a resource several steps are involved.

  1. request the resource.
  2. use the resource.
  3. release the resource.

If the resource is currently being used the process must wait for the resource to become available.

Formal Definition Edit

A set of processes are deadlocked if each process in the set is waiting for an event that only another process in the set can cause.

A deadlock ensures that no processes can run, release resources be awakened.

Conditions for Deadlock Edit

  1. Mutual exclusion condition - resource can only be given to a single process
  2. Hold and wait condition - process holding resources can request additional
  3. No preemption condition - previously granted resources cannot forcibly taken away
  4. Circular wait condition - must be a circular chain of 2 or more processes each is waiting for resource held by next member of the chain

Deadlock Strategies Edit

Ignore Edit

Not so good ey

It is reasonable if deadlocks are rare and the cost to prevent/recover is quite high. Unix and windows do use this method with more complex deadlock situations.

Detect and Recover Edit

Detection
DfgdfgPicture 22

A method to detect a potential dead lock is to form two tables. Table on the left contains all the possible resources and where they are allocated. The table on the right contains all the resources currently not in use and the upcoming requests. To find a deadlock search through the request matrix for a request row whos values are lower than the resources available. If it is found the process can complete and the resources are then released. Add the released resources to the resources available and repeat. If no such row can be found the remaining processes are then deadlocked. If the algorithm finds that all the resources are released then there is no deadlock.

Once a deadlock has been detected we need to recover from it.

Recover through


  • Preemption - take resources back
  • Rollback - save process state periodically and roll back if we encounter deadlock
  • Kill - kill processes until deadlock is resolved.

Dynamic Avoidance Edit

Safe State

Is a state when the system is not deadlocked. There exists a scheduling order that results in every process running to completion, even if they all request their maximum resources immediately

Unsafe State

An unsafe state does not necessarily that the system will result in deadlock, it could be lucky and complete with out and issue. We can however not guarantee that the system will complete (not deadlock).

A deadlock avoidance algorithm in essence only adds processes that will ensure safe status.

Bankers Algorithm

Processes are only allowed to proceed if there are enough resources to accommodate their maximum possible request. Otherwise they have to wait for other processes to return resources before continuing. Although the bankers algorithm will prevent a deadlock it is impractical to know the maximum number of resources required in advanced.

Prevention Edit

Resource policies are used to ensure that one of the 4 conditions for deadlock are not met.

Mutual Execlusion

It is not feasible in general to attack this condition as some resources can not be shared.

Hold and Wait

Simply require processes to request all resources necessary for completion before starting. This can cause issues with processes unaware of which resources are required. It also does not allow for resources to be used effectively as some resources may be held by processes not currently using them. Several variations exist such as process giving up all of its resources if it blocks whilst holding a resource, then immediately request all the resources needed. This although can lead to starvation.

Preemption

Simply take resources from processes. Not viable as many resources cannot be preempted. IE printer.

Circular Wait

A common approach to attacking circular waiting is to enforce a policy that forces processes to acquire resources in a specified order. This ensures that resources are acquired and released circularly, ensuring that processes cannot block one another.

Starvation Edit

Starvation is a situation where the overall system continues to make progress but a particular process is not given the necessary resources or processor time to progress.

Starvation maybe caused by:


  • Never being allocated resources - always in blocked state
  • Never being scheduled to run
  • etc

The easiest strategy to prevent starvation is to enforce a first come first served scheduling and resource allocation algorithm.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.