首页 > 试题广场 >

Jurassic Park consists of a di

[问答题]

  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, wait() and signal() to synchronize the m passenger processes and the n car processes. 



六、 Answer 15 pts

semaphores:

var car_available := n; var passenger_wait := 0;

process passenger(i := 1 to num_passengers) wandering for a random time; signal(passenger_wait); wait(car_available);

end passenger

process car(i := 1 to num_cars) wait(passenger_wait); take passenger wandering; signal(car_available);

end car


发表于 2017-05-16 21:27:11 回复(0)