Lab notes
Course lectured by Prof. Gabriel Kuper Lab assist. Ilya Zaihrayeu http://www.dit.unitn.it/~ilya/os.htm
Deadlock Prerequisites
Deadlock can arise if four conditions hold simultaneously: Mutual exclusion: only one process at a time can use a resource. If another process requests that resource, the requesting process is delayed until the resource is released; Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes; No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task; Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0
Ilya Zaihrayeu Operating Systems Course
2
Deadlock Prevention
Mutual Exclusion not required for sharable resources; for non-sharable resources generally not possible to prevent deadlocks by denying the mutual-exclusion condition a possible solution – a spooler Hold and Wait Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none No Preemption If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released Circular Wait impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration
Ilya Zaihrayeu Operating Systems Course
3
Traffic deadlock example
Q: Consider the traffic deadlock represented on the right
(a) Show that the 4 necessary conditions for deadlock indeed hold in this example (b) State a simple rule that will avoid deadlocks in the system