User OS Kernel & Device Drivers Interface Programs
Deadlock
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems
1
Deadlocks
• Computer resources are full of resources that can only be used by one process at a time • Unpredictable results can occur if two or more processes use the same resource at the same time • OS control this problem by arbitrating resource requests • OS grant exclusive access and manage access to system resources • By allowing processes to have exclusive access to resources problems may occur:
– Starvation – Deadlock
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems
2
Deadlocks
• Deadlock can occur if two or more processes are competing for two or more common resources • Deadlock causes all processes involved in the deadlock to become permanently blocked
– Each process is waiting on resources owned by other processes that are also deadlocked
• Deadlock may be difficult to detect
– Often timing sensitive
• What to do about deadlocks:
– – – – Understand them Model them Develop ways to detect them Develop ways to avoid them
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 3
Resources
• Deadlocks occur when processes have been granted exclusive access to resources
– Resources include semaphores, devices, files, …
• Resources come in two types:
– Preemptive resource: A resources that can be taken away from a process without any ill effects.
• Example: memory
– Non-preemptive resource: A resource that can not be taken safely away from a process
• Example: printer
• Deadlocks generally involve non-preemptive resources • Deadlocks can be easily fixed with preemptive resources
– Take resources away from one or more deadlocked processes
Brian Mitchell (bmitchel@mcs.drexel.edu) Operating Systems 4
Using Resources
• Access to resources should follow the model presented when we discussed critical sections
– Request the resource – Use the resource –