COMP5126 Distributed System Programming Lab 7: Usage of Monitors 1. The Roller Coaster Problem. 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. Develop a monitor (i.e. pseudo-code) to synchronise the passenger and car processes. The monitor should have three operations: takeRide, which is called by the passengers, and load and unload, which are called by the car process. Use the Signal and Continue discipline. 2. a) Write an MPD program to simulate the Dining Philosophers problem described in Section 4.3 of the text. There should be five processes, one per philosopher and one “monitor” for the table to synchronise the philosophers. The monitor should have two methods: getforks(id) and relforks(id), where id is an integer between 1 and 5 representing the process id. Your program should have one command-line argument rounds that specifies the number of rounds of thinking and eating that each philosopher should execute. The philosophers should eat and think random amounts of time. Add print statements to your program to generate a trace of activity of the program. Your program should print a trace of interesting events in the program. These events include when a process call getforks, start to eat, calls relforks and start to think. For each event, print a line containing a timestamp (from age() function), a process id and a string describing the event. For example, a line of the trace might look like: 12345: b) Philosopher 4 calls getforks() Your program for part (a) should allow a philosopher to start eating as long as neither neighbour is eating. This can, however lead to starvation if the processes were to execute forever: One philosopher could be unlucky enough that at all times one of the other of its neighbours is eating, even though each neighbour repeatedly eats and thinks. Modify your program so that philosophers get to start eating in FIFO (or FCFS) order. This means that if one philosopher has to wait to get permission to eat (because a neighbour is eating) and a second philosopher calls getforks, the second philosopher must wait, even if neither of its neighbours is eating. Hint: Use the Ticket algorithm (Section 3.3.2) to order the waiting philosophers in getforks. 1 of 1