Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.

Similar presentations


Presentation on theme: "1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is."— Presentation transcript:

1 1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is in control. - Anonymous

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

3 3 §Starvation means there exists a path to making progress but the scheduler is not choosing it. §Deadlock means there is no such path.

4 4 System Model §Resource types R 1, R 2,..., R m CPU cycles, memory space, I/O devices §Each resource type R i has W i instances. §Resources may be logical as well as physical.

5 5 Mode of operation Process may utilize a resource in only the following sequence. §Request §Use §Release §Request and release are system calls e.g system calls for allocation and freeing of memory, open and close file system calls, wait and signal on semaphores etc.

6 6 The Deadlock Problem §A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. §Example l System has 2 tape drives. l P 1 and P 2 each hold one tape drive and each needs another one. §Example l semaphores A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A)

7 7 Deadlock Characterization §Mutual exclusion: only one process at a time can use a resource. §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. Deadlock can arise if four conditions hold simultaneously.

8 8 Deadlock Characterization §Circular wait: there exists a set {P 0, P 1, …, P 0 } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, P n–1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0. Deadlock can arise if four conditions hold simultaneously.

9 9 Resource-Allocation Graph §V is partitioned into two types: l P = {P 1, P 2, …, P n }, the set consisting of all the processes in the system. l R = {R 1, R 2, …, R m }, the set consisting of all resource types in the system. §request edge – directed edge P 1  R j §assignment edge – directed edge R j  P i A set of vertices V and a set of edges E.

10 10 Example of a Resource Allocation Graph

11 11

12 12

13 13 Basic Facts §If graph contains no cycles  no deadlock. §If graph contains a cycle  l if only one instance per resource type, then deadlock. l if several instances per resource type, possibility of deadlock.

14 14 Mode of operation §System table records whether each resource is free or allocated, and if allocated, to which process §If a process requests a resource that is currently allocated to another process, it can be added to a queue of processes waiting for this resource

15 15 Handling Deadlocks §Use a protocol to prevent or avoid deadlocks. §Allow a system to enter deadlock state, detect it and recover. §Ignore the problem altogether.

16 16 Handling Deadlocks §What can happen if processes in the system are in state of undetected deadlock?

17 17 Deadlock Prevention §Mutual Exclusion §Hold and Wait §No pre-emption §Circular Wait

18 18 Deadlock Prevention Side effects of deadlock prevention : Low resource utilization and throughput

19 19 Deadlock Avoidance §Deadlock avoidance requires additional information about about how resources are to be requested. It decides whether the current request is to be satisfied or not. §Decision is based on currently available resources and currently allocated resources and future requests of processes.

20 20 Deadlock Avoidance §Deadlock Avoidance algorithm requires each process declare the maximum number of resources of each type it might need. §It dynamically examines the resource allocation state to ensure circular wait condition can never exist. §Resource allocation state is defined by: l number of available resources l number of allocated resources l maximum demands of processes

21 21 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.

22 22 Safe State §Sequence is safe if for each P i, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the P j, with j<i. l If P i resource needs are not immediately available, then P i can wait until all P j have finished.

23 23 Safe State l When P j is finished, P i can obtain needed resources, execute, return allocated resources, and terminate. l When P i terminates, P i+1 can obtain its needed resources, and so on. If no such sequence exists, then system state in unsafe.

24 24 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.

25 25 Safe, Unsafe, Deadlock State

26 26 §Example.

27 27 Resource-Allocation Graph Algorithm §Claim edge P i  R j indicated that process P j may request resource R j ; represented by a dashed line. §Claim edge converts to request edge when a process requests a resource. §Resources must be claimed a priori in the system.

28 28 Resource-Allocation Graph For Deadlock Avoidance

29 29 Unsafe State In Resource-Allocation Graph

30 30 Banker’s Algorithm §Multiple instances. §Each process must a priori claim 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.

31 31 Banker’s Algorithm §Resources requested by process must not exceed the total available in the system. §Algorithm allocates resources if allocation leaves system in a safe state

32 32 Data Structures for the Banker’s Algorithm §Available: Vector of length m. If available [j] = k, there are k instances of resource type R j available. §Max: n x m matrix. If Max [i,j] = k, then process P i may request at most k instances of resource type R j. Let n = number of processes, and m = number of resources types.

33 33 Data Structures for the Banker’s Algorithm §Allocation: n x m matrix. If Allocation[i,j] = k then P i is currently allocated k instances of R j. §Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. Let n = number of processes, and m = number of resources types.

34 34 Safety Algorithm 1.Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i - 1,3, …, n. 2.Find and i such that both: (a) Finish [i] = false (b) Need i  Work If no such i exists, go to step 4. 3.Work = Work + Allocation i Finish[i] = true go to step 2. 4.If Finish [i] == true for all i, then the system is in a safe state.

35 35 Resource-Request Algorithm for Process P i Request = request vector for process P i. If Request i [j] = k then process P i wants k instances of resource type R j. 1.If Request i  Need i go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim. 2.If Request i  Available, go to step 3. Otherwise P i must wait, since resources are not available.

36 36 Resource-Request Algorithm for Process P i 3.Pretend to allocate requested resources to P i by modifying the state as follows: Available = Available - Request i ; Allocation i = Allocation i + Request i ; Need i = Need i – Request i If safe  the resources are allocated to P i. If unsafe  P i must wait, and the old resource-allocation state is restored


Download ppt "1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is."

Similar presentations


Ads by Google