Presentation is loading. Please wait.

Presentation is loading. Please wait.

Resource Management: Chap 9 Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets.

Similar presentations


Presentation on theme: "Resource Management: Chap 9 Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets."— Presentation transcript:

1 Resource Management: Chap 9 Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets

2 Reusable Data Structures const int M = 10;/* # of resources*/ typedef unsigned int ResourceVec[M]; ResourceVec available, /* # unallocated */ total; /*maximum possible units*/

3 Reusable Data Structures const int N = 5; /* # of processes*/ typedef struct { ResourceVec allocation, /*owned*/ request, /*unsatisfied requests*/ maxClaim; /*only for batch */ } PerProcess; /*process*/

4 Resource State Diagram Process 1 2 3 Resource avail total 12+(1)+[1] 1 [2] 0 3 2 2 1+[1] 1+(1)+[1] 0 2 3 3 1+(1)[1] 1 0 2 3 RESOURCES 3 PROCESSES Process 1 owns 2 units of R1, has requested 1 more with a remaining claim of 1 unit. There are no R1 units avail.

5 Deadlock No Effective Deadlock A request must be granted in finite time even if new requests are accepted. No Deadlock A request must be granted in finite time assuming that no further requests are accepted.

6 Effective Deadlock Example Process 1 2 3 Resource avail total 1 1+[1] (2)+[2] 1+[1] 0 2 Processes 1 and 3 overlap requests for 1 unit at a time. Process 2’s request for 2 units is never satisfied.

7 Necessary Conditions (1) Processes claim exclusive control. (2) Processes hold resources while requesting additional resources. (3) Resources cannot be forcibly removed (preempted) from processes. (4) A circular chain of processes exist such that each process holds one or more of the resources requested by its predecessor in the chain. If not, one of the processes would eventually receive a resource that it needed to complete.

8 Solution Classes Prevention  Static, works before programs execute Avoidance  Dynamic, check every request for safety Detection/Recovery  Check for “stuck” processes at intervals

9 Prevention No exclusive control -- share everything No incremental requests 1.Collective requests 2.Release all before requesting more Allow preemption Havender’s Ordered Requests request a resource in class C(i) only if it holds no resources in any class C(j), j>=i. Dijkstra’s Minimal Progress

10 Havender Ordered Request Example Class Resource Type 6 Printer 5 Disk 1 4 Tape Drives 1 and 2 3 Disk 2 2 Tape Drives 3 and 4 1 Memory

11 Avoidance A request is granted only if it results in a SAFE resource state. Requires Max Claim information. A safe execution sequence is an execution schedule of processes (P1, P2,..., Pn) such that for each P(i), when it begins execution, its maximal claims can be satisfied by the available resources.

12 A Safe State Process 1 2 3 Resource avail total 11+[4] 3+(1)+[4] 3+[3] 3 10 Safe Execution Sequences = (P3, P1, P2) (P3, P2, P1)

13 An Unsafe State Process 1 2 3 Resource avail total 11+(1)+[4] 4+[3] 3+[3] 2 10 NO Safe Execution Sequence exists!

14 Banker’s Algorithm On every request, search for a SES such that  Every process can have its MAXIMUM CLAIM satisfied in at least one execution order Most Liberal because it gives away all resources if possible at the cost of execution order flexibility

15 Banker’s Algorithm avail = available; /*copy the current state*/ for (i=0; i<N; i++) canFinish[i]=false; for ( ;; ) { i = 0; allInSES = true; for ( ;; ) { if ( !canFinish[i] ) { /*am I already in SES*/ if (vGeq(avail, i)) { /*no, can I get resources?*/ vAdd(avail, i); /*yes, then I can finish and*/ canFinish[i] = true; /*add resources to "avail"*/ break; /*I am now in the SES*/ } else allInSES = FALSE; /*>=1 is still delayed*/ } /*if*/ if (++i >= N) return allInSES; /*exit with answer*/ } } /*for for*/

16 Detection and Recovery For single-unit resources (semaphores/files), a cycle is a necessary and sufficient condition for deadlock.

17 Detection and Recovery Process 1 2 3 4 Resource available total 1 1+(1) 1 (1) 1 0 3 2 1+(1) 1 0 0 2 A cycle (P1 P2) exists but no deadlock because P4 can terminate and give a resource back.

18 Recovery Options Terminate operating system Terminate all processes in a cycle Terminate one process in a cycle Preempt resources


Download ppt "Resource Management: Chap 9 Reusable  Disk blocks  File descriptors  Semaphores Consumable  Messages  Packets."

Similar presentations


Ads by Google