Suppose there are n passenger processes, and one car process. The passengers rep
ID: 3880760 • Letter: S
Question
Suppose there are n passenger processes, and one car process. The passengers repeatedly wait to take rides in the car, which can hold C passengers (C n). However, the car can go around the tracks only when it is full.
You need to do the following:
Develop code for the actions of the passenger and car processes. Use message passing for communication.
Generalize your answer to employ m car processes (m ¡ 1). Since there is only one track, cars cannot pass each other, i.e., they must nish going around the track in the order in which they started. Again, a car can go around the tracks only when it is full.
Write a report to explain your algorithm, and what communication pattern you used in your code. Is it possible to use another communication pattern? If so, what about the communication complexity and computational complexity?
pseudo code
N-Body.pdf × #.hw1.docx 3.2 Your Tasks You need to do the following 1. Develop code for the actions of the passenger and car processes. Use message passing for communication. 2. Generalize your answer to employ m car processes (m > 1). Since there is only one track, cars cannot pass each other, i.e., they must finish going around the track in the order in which they started. Again, a car can go around the tracks only when it is full. 3. Write a report to explain your algorithm, and what communication pattern you used in your code. Is it possible to use another communication pattern? If so, what about the communication complexity and computational complexity? 3.3 What to Hand In Submit the following 1. Pseudo code. 2. Your reportExplanation / Answer
Shared data: semaphore avail_seat=C, riders=0, seats_taken=0;
Each of the n passenger processes:
while (1) {
wait(avail_seat); // wait in line
signal(seats_taken); // claim a seat and sit in it
// now sitting in car waiting for ride to complete
wait(riders); // wait for car to signal the end of the ride
}
The car process:
while (1) {
int counter; // local variable - no mutex needed
for (counter=0; counter<C; counter++) {
wait(seats_taken); // wait for each seat to be filled by a passenger
}
// go around the tracks
for (counter=0; counter<C; counter++) {
signal(riders); // tell this riding passenger that they can leave
signal(avail_seat); // signal waiting passengers that a seat is open
// for the next trip around the tracks } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.