40 Points) (Name) (Section
Total Page:16
File Type:pdf, Size:1020Kb
Grading: 3 = correct 2 = almost Homework #4 ______(40 points)1 = an attempt (Name) (Section) 0 = nothing Score: Points / Possible Chapter 5 - Mutual Exclusion Chapter 6 – Concurrency and Deadlock Questions: Answers: 1. (5.19) (9 points) The following was once used on an exam:
Jurassic Park consists of a dinosaur museum and a park for safari riding. There are m passengers and n single-passenger cars. Passengers wander around the museum for a while, then line up to take a ride in a safari car. When a car is available, it loads the one passenger it can hold and rides around the park for a random amount of time. If the n cars are all out riding passengers around, then a passenger who wants to ride waits; if a car is ready to load but there are no waiting passengers, then the car waits. Use semaphores to synchronize the m passenger processes and the n car processes.
The following skeleton code was found on a scrap of paper on the floor of the exam room. (Note: W and S correspond to semWait and semSignal. Additionally, there is a process created for each passenger and car.) Ignoring syntax and missing variable declarations,
a. Grade it (and justify your grade) for correctness (ie deadlock, starvation, mutual exclusion, etc.). b. How does weak verses strong semaphores effect the rides? c. If there are problems, how would you fix them?
01 resource Jurassic_Park() 02 sem car_avail := 0; 03 sem car_taken := 0; 04 sem car_filled := 0; 05 sem ride_done := 0; 06 07 process passenger(i := 1 to num_passengers) 08 do true -> 09 nap(int(random(1000*wander_time))); 10 W(car_avail); 11 S(car_taken); 12 W(car_filled); 13 W(ride_done); 14 od 15 end passenger 16 17 process car(j := 1 to num_cars) 18 do true -> 19 S(car_avail); 20 W(car_taken); 21 nap(int(random(10*fill_time))); 22 S(car_filled); 23 nap(int(ramdom(1000*ride_time))); 24 S(ride_done); 25 od 26 end car 27 end Jurassic_park
BYU, CS 345, F2011 Homework #4 Page 1/3 2. (6.1) (4 points) All cars arrived at an intersection at the same time. In such situations, the law requires the car on the left to yield to the car on the right. Show that the four conditions of deadlock apply.
3. (6.5) (15 points) Consider the following snapshot of a system. There are no outstanding unsatisfied requests for resources.
CurrentAvailable Allocation r1 r2 r3 r4 Maximum Demand r12 r21 r30 r40 r1 r2 r3 r4
P1 0 0 1 2 0 0 1 2
P2 2 0 0 0 2 7 5 0
P3 0 0 3 4 6 6 5 6
P4 2 3 5 4 4 3 5 6
P5 0 3 3 2 0 6 5 2
a. Compute what each process still might request and display in the columns labeled “still needs”. b. Is this system currently in a safe or unsafe state? Why? c. Is this system currently deadlocked? Why or why not? d. Which processes, if any, are or may become deadlocked? e. If a request from P3 arrives for (0,1,0,0), can that request be safely granted immediately? In what state (deadlock, safe, unsafe) would immediately granting that whole request leave the system? Which processes, if any, are or may become deadlocked if this whole request is granted immediately? 4. (6.6) (6 points)Apply the deadlock detection algorithm of Section 6.4 to the following data and show the results:
Available = | 2 1 0 0 |
| 2 0 0 1 | | 0 0 1 0 | Request = | 1 0 1 0 | Allocation = | 2 0 0 1 | | 2 1 0 0 | | 0 1 2 0 |
BYU, CS 345, F2011 Homework #4 Page 2/3 5. (6.11) (6 points) Consider a system with a total of 150 units of memory, allocated to three processes as shown:
Process Max Hold 1 70 45 2 60 40 3 60 15
Apply the banker’s algorithm to determine whether it would be safe to grant each of the following requests. If yes, indicate a sequence of terminations that could be guaranteed possible. If no, show the reduction of the resulting allocation table. a. A fourth process arrives, with a maximum memory need of 60 and an initial need of 25 units. b. A fourth process arrives, with a maximum memory need of 60 and an initial need of 35 units.
BYU, CS 345, F2011 Homework #4 Page 3/3