CS162 Spring 2001

Section 107

Jeryl Soto Contemprato

cs162-td@cory.eecs.berkeley.edu

 

Discussion Notes

27 February 2001

 

Admin

 

Nachos

 

Deadlock

1)                 Mutual exclusion:  at least 1 resource in consideration has to be nonsharable, so that only 1 process at a time can use it.  So if another ps. requests it, that requester blocks until rsc is released

2)                 Hold & wait:  Need a process holding at least 1 resource & waiting to get add’l rscs but are currently held by other ps.s

3)                 No preemption:  resources cannot be preempted (kinda like #1)

4)                 Circular wait:  like #2, we have hold & wait except it occurs in every process (given some set of processes) in a roundabout fashion.

1)      Thread X requests resource.  If the Request > Need[x], then raise an error (A’s maxNeed claim exceeded)

2)      If Request > Avail, then thread A must wait until there is enough available (i.e. wait until Request <= Avail)

3)      “Simulate” allocation of the requested resource by modifying the resource allocation table:

Now we check if resulting state is safe.  If so, we actually make the allocation.  If not, undo the simulation and make X wait on the resource again (we’ll try again when someone returns some of the resource back to the system)

1)      We are determining state for one resource.  So initialize Work := Avail (a working variable for how much of a resource will be available), and a vector Finish (with one entry for every process) so that Finish[x] := false for all x

2)      Find an process x so that both

a.       Finish[x] = false

b.      Need[x] <= Work

This looks for a thread that has not “finished” in this simulation and whose need is less than the currently available amount of resource for this simulation, in other words it’s looking for a thread that hasn’t “finished” but whose future requests we can support.  If we can’t find any such process, jump to 4.

3)      We found a process whose future requests (i.e. amount process will need = Need) we can support for now.  So we pretend that the process x has finished by returning the resources was holding to Work, so that Work := Work + Alloc[x], and set finish[x] = true.  Go back to step 2 to try and hook up another process

4)      If we got here that means either all processes can finish, or that we were unable to supply the need for at least one process (even after “finishing” as many other processes as we could and “returning” those resources).  If finish[x] = true for all x then we know we’re safe.

 

CPU Scheduling