can any one help me solve this qestion

Jurassic Park consists of a dinosaur museum and a park for safari tiding. There are n passengers and m 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 m cars are all out riding passenger around, the 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 n passenger threads/processes and the m car threads/processes.

Niharika, assuming that you know well what a semaphore means.

Assume that we have two primitive procedures available for passengers, wander_around() & take_a_ride() & one primitive procedure available for cars, give_a_ride() (with the obvious semantics). Using semaphores for synchronization, we’ll write two procedures, passenger for passengers & car for cars, respectively. Assume that semaphores unblock on a First In First Out(FIFO) basis.
Solution(pseudocode):-

Semaphore CarAvailable = 0
Semaphore PassengerAvailable = 0
Passenger ( )
{
Wander_Around ( ) ;
up( PassengerAvailable ) ;
down( CarAvailable ) ;
Take_a_ride ( ) ;
}
Car ( )
{
While (TRUE)
{
down( PassengerAvailable ) ;
up( CarAvailable ) ;
Give_ a_ride ( ) ;
}
}

[Hint : It does not depend on either the number of passenger or the cars]
Related Question : http://www.codechef.com/problems/NI01

2 Likes

we are not here to solve your assignments. also this is not related to competitive programming.