Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a multi-thread/process C program using the following statement. Jurassic P

ID: 3931297 • Letter: W

Question

Write a multi-thread/process C program using the following statement.

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.

Explanation / Answer

passReady = semaphore(0)

carAvail = semaphore(n)

unloadPass = semaphore(0)

loadPass   = semaphore(0)

class passenger(Thread):

def __init__(self,pNo):

self.passengerNo=pNo

def run(self):

while True:

wander around museum

passReady.signal()

carAvail.wait()

loadPass.wait()

ride car through park

unloadPass.wait()

class car(Thread):

def __init__(self,cNo):

self.carNo=cNo

def run(self):

while True:

passReady.wait()

loadPass.signal()

travel through park

unloadPass.signal()

carAvail.signal()

passengers = [passenger(i) for i in range(m)]

cars = [cars(i) for i in range(n)]

for i in range(m):

passengers(i).start()

for i in range(n):

cars(i).start()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote