Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a playground, there is train that takes passengers for a tour. The train begins the tour only when its full. Assume that, we have

In a playground, there is train that takes passengers for a tour. The train begins the tour only when its full. Assume that, we have 'n' number of passengers and only one train. Passengers can go several times for a tour, but every time a passenger wants to go for a tour he/she has to wait and check if there is an empty seat in the train. The train can hold a maximum 'k' number of passengers so when the train comes it declares the maximum number. Use semaphore to solve the problem of synchronizing passengers and the train, take the following into consideration:
The train starts the tour only when it is full; has k passengers
when the tour finishes, each passenger gets off the train
no passenger is allowed to get off while the train in driving, and cannot request another tour until he/she gets off the train.
To manage passengers;
assume that there is a queue
the queue is managed by the gate keeper of the train
passengers checks in one-by-one
last passenger informs the train that all passengers are in the train to start the tour
at the end of the tour, passengers gets off the train on-by-one
To manage the train
when the train arrives the gate, informs the gate keeper that it is ready, in order to let passengers check in
block the train from running until it has the k number of passengers
the train starts the tour when last passenger checks in
when the train comes from the tour, it waits until all passengers get off then it can go for another round
In your submission, make the following clear
shared semaphores; declarations and value assignment, add comment to explain for what each semaphore is used
code of the Passenger and the Train, add comment to explain the code
chart explaining your solution
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions