Assignment No. 3 Muhammad Faizan Karim (MC110402217) : (Solution)
Assignment No. 3 Muhammad Faizan Karim (MC110402217) : (Solution)
(Solution) Several data structures must be maintained to implement the bankers algorithm. These data structures encode the state of the resource-allocation system. Let n be the number of processes in the system and m be the number of resource types. We need the following data structures: . Available: ! vector of length m indicates the number of available resources of each type. "fAvailable[j]=k# there are k instances of resource type Rj available. $. Max: !n nm matri% defines the ma%imum demand of each process. "f Max [i,j]=k# then process Pi may re&uest at most k instances of resource type Rj. '. Allocation: !n nm matri% defines the number of resources of each type currently allocated to each process. "f Allocation [i,j]=k# then process Pi is currently allocated k instances of resource type Rj. (. Need: !n nm matri% indicates the remaining resource need of each process. "f Need [i,j]=k# then process Pi may need k more instances of resource type Rj to complete its task. Need [i,j]=Max[i,j]-Allocation[i,j] The algorithm for finding out whether or not a system is in a safe state can be: Let Work and )inish be vectors of length m and n# respectively. "nitiali*e Work: =Available and Fini ! +i,:="al e for i=#,$,%,n . )ind an i such that both a& Fini !+i, ="al e b& Needi-Work "f no such i e%ists# go to step (. $. Work: =Work'Allocationi Fini !+i,:=tr(e go to step $. '. "f Fini !+i, =tr(e for all i# then the system is in a safe state. This algorithm may re&uire an order of mn) operations to decide whether a state is safe. .onsider the system with five processes /0 through /( and four resource types A, *, +, and ,. !llocated 0 $ 0 0 1eed 0 $ 0 0 ' !vailable 0 $ ' $ 3 ' $ 3 (
0 0 0
0 0 0
0 0 0
$ 0 0
0 $ '
$ $