For the Cricket World Cup 2021, a fly-over has been constructed between the hotel where the teams
Question:
For the Cricket World Cup 2021, a fly-over has been constructed between the hotel where the teams are staying and the stadium. This fly-over will be used by the Pakistan team and the Indian team in the upcoming semifinal on Sunday. A tram car is used to cross this fly-over, but it seats only four people, and must always carry a full load.
We cannot put three Pakistan’s and one Indian in the same tram-car, because the Pakistani’s would be in majority and might try to intimidate the Indian. Similarly, we cannot put three Indian in the same tram-car with one Pakistani. All other combinations are safe.
You are required to code two processes; the first shall simulate the arrival of Indian players and other the arrival of Pakistani players. These players can come at any time, in any order to cross the fly over. The first process shall call a procedure called IndianHere on the arrival of an Indian player. Similarly, the second process shall call a procedure called PakistanHere on the arrival of a Pakistan player. As soon as a safe combination is reached, the tram starts and crosses to other side. Assume that a tram is always available when required.
Use semaphores to implement the solution. The Indian and Pakistan’s should not wait if there are enough of them for a safe tram-car load. The two processes will simulate the arrival of players at random intervals and should run for a while to show around 10 trams leaving with different safe combinations. Before terminating you must clean up the semaphores and shared memory segments from the system. You must output the progress of the processes. E.g., when a player arrives, you should output who arrived and also print the total number of Indians and Pakistan’s waiting to board the tram. When a tram leaves you should output that as well. Your code should include well written comments and at the beginning, you should explain your strategy for solving the problem.
College Accounting A Contemporary Approach
ISBN: 978-0073396958
2nd edition
Authors: David Haddock, John Price, Michael Farina