Download presentation
1
DPNM Lab. Dept. of CSE, POSTECH
ITEC 502 컴퓨터 시스템 및 실습 Chapter 4-2: Deadlock Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH
2
Contents Deadlock avoidance Deadlock prevention Other issues
ITEC502 컴퓨터 시스템 및 실습
3
Deadlock Avoidance Requires that the system has some additional a priori information available Simplest and most useful model for DA requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes ITEC502 컴퓨터 시스템 및 실습
4
Resource Allocation State: Safe, Unsafe , Deadlock
ITEC502 컴퓨터 시스템 및 실습
5
Safe State When a process requests an available resource,
system must decide if immediate allocation leaves the system in a safe state System is in safe state? if there exists a safe sequence of all processes Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j<i If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed resources, and so on ITEC502 컴퓨터 시스템 및 실습
6
Basic Facts If a system is in safe state no deadlocks
If a system is in unsafe state possibility of deadlock Avoidance ensure that a system will never enter an unsafe state ITEC502 컴퓨터 시스템 및 실습
7
Deadlock Avoidance Resource Trajectories
Two process resource trajectories ITEC502 컴퓨터 시스템 및 실습
8
Safe and Unsafe States (1)
(a) (b) (c) (d) (e) Demonstration that the state in (a) is safe ITEC502 컴퓨터 시스템 및 실습
9
Safe and Unsafe States (2)
(a) (b) (c) (d) Demonstration that the sate in b is not safe ITEC502 컴퓨터 시스템 및 실습
10
Banker’s Algorithm Deadlock avoidance algorithm Assumption:
Resource-Allocation Graph is not applicable to a resource allocation system with multiple instance of each resource type Supports multiple instances Named because this algorithm could be used in a bank Assumption: Each process must make a priori claim for maximum use When a process requests a resource it may have to wait When a process gets all its resources it must return them in a finite amount of time Two sub-algorithms Safety Algorithm Resource-Request Algorithm ITEC502 컴퓨터 시스템 및 실습
11
The Banker's Algorithm for a Single Resource
(a) (b) (c) Three resource allocation states safe unsafe ITEC502 컴퓨터 시스템 및 실습
12
Banker's Algorithm for Multiple Resources
Example of banker's algorithm with multiple resources ITEC502 컴퓨터 시스템 및 실습
13
Deadlock Prevention (1)
By ensuring that at least one of the four conditions for deadlock cannot hold, we can prevent deadlock Restrain the ways request can be made Mutual Exclusion Hold and Wait No Preemption Circular Wait ITEC502 컴퓨터 시스템 및 실습
14
Deadlock Prevention Attacking the Mutual Exclusion Condition
not required for sharable resources (read-only file) must hold for nonsharable resources (printer) Some devices (such as printer) can be spooled only the printer daemon uses printer resource thus deadlock for printer eliminated Not all devices can be spooled Principle: avoid assigning resource when not absolutely necessary as few processes as possible actually claim the resource ITEC502 컴퓨터 시스템 및 실습
15
Attacking the Hold and Wait Condition
Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources 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 Require processes to request resources before starting a process never has to wait for what it needs Problems may not know required resources at start of run also ties up resources other processes could be using Low resource utilization; starvation possible Variation process must give up all resources then request all immediately needed ITEC502 컴퓨터 시스템 및 실습
16
Attacking the No Preemption Condition
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 Preempted resources are added to the list of resources for which the process is waiting Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting This is not a viable option Consider a process given the printer halfway through its job now forcibly take away printer !!?? ITEC502 컴퓨터 시스템 및 실습
17
Attacking the Circular Wait Condition
impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration (a) (b) Normally ordered resources A resource graph ITEC502 컴퓨터 시스템 및 실습
18
Summary to Deadlock Prevention (1)
ITEC502 컴퓨터 시스템 및 실습
19
Summary to Deadlock Prevention (2)
Deadlock prevention algorithm Prevent deadlocks by restraining how requests can be made The restraints ensures that at least one of the necessary conditions for deadlock cannot occur and, hence, that deadlocks cannot hold Possible side effects deadlock prevention Low device utilization Reduced system throughput Alternative method Deadlock Avoidance ITEC502 컴퓨터 시스템 및 실습
20
Other Issues: Two-Phase Locking
Phase One process tries to lock all records it needs, one at a time if needed record found locked, start over (no real work done in phase one) If phase one succeeds, it starts second phase, performing updates releasing locks Note similarity to requesting all resources at once Algorithm works where programmer can arrange program can be stopped, restarted ITEC502 컴퓨터 시스템 및 실습
21
Non-resource Deadlocks
Possible for two processes to deadlock each is waiting for the other to do some task Can happen with semaphores each process required to do a down() on two semaphores (mutex and another) if done in wrong order, deadlock results ITEC502 컴퓨터 시스템 및 실습
22
Starvation Algorithm to allocate a resource
may be to give to shortest job first Works great for multiple short jobs in a system May cause long job to be postponed indefinitely even though not blocked Solution: First-come, first-serve policy ITEC502 컴퓨터 시스템 및 실습
23
Summary A deadlock requires that four conditions hold simultaneously
Mutual exclusion, hold and wait, no preemption, circular wait Four principle methods for dealing with deadlocks Ignore the deadlock problem Deadlock detection-recovery scheme Deadlock avoidance Deadlock prevention Deadlock avoidance requires a priori information such as the maximum number of each resource classes Bankers algorithm Deadlock prevention ensures that at least one of the necessary conditions never holds ITEC502 컴퓨터 시스템 및 실습
24
Review Deadlock avoidance Deadlock prevention Other issues
ITEC502 컴퓨터 시스템 및 실습
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.