Problem

The following problem was once used on an exam:Jurassic Park consists of a dinosaur museum...

The following problem 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. Grade it for correctness. Ignore syntax and missing variable declarations. Remember that P and V correspond to semWait and semSignal.

resource Jurassic_Park()

 sem car_avail := 0, car_taken := 0, car_filled := 0, passenger_released := 0

process passenger(i := 1 to num_passengers)

 do true -> nap(int(random(1000*wander_time)))

  P(car_avail); V(car_taken); P(car_filled)

  P(passenger_released)

 od

 end passenger

  process car(j := 1 to num_cars)

  do true -> V(car_avail); P(car_taken); V(car_filled)

  nap(int(random(1000*ride_time)))

  V(passenger_released)

   Od

 end car

end Jurassic_Park

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5