Lab 6 (Week 8)
Process Synchronization using Monitors
Purpose
After completing the exercises in this week (Lab 6), You will gain a better understanding through visual representation of both the classical Dining Philosophers problem as well as how monitors operate.
In this lab, you will explore a simulation software (created by Steve Robbins) named “Starving Philosphers simulator”.
Although this simulator is termed “Starving” Philosophers, you will not mainly use this simulator to illustrate a concept about “starvation”. Rather, throughout the task of this lab, you will be able to understand how monitors work and how processes move between various internal queues of the monitor (the entry and wait queues) as well as how the monitor lock is used.
You will be also encouraged to devise algorithms for preventing starvation in the final question given at the end of today’s task.
Prerequisites
This simulator is mainly related to topics covered in Section 6.6 and 6.7.
Before starting this lab, you should be familiar with the Dining Philosophers problem (which is presented in Section 6.6.3) as well as monitors (which is presented in Section 6.7).
Starting the Simulator
Download the Starving Philosophers simulator (sp.zip) from LearnJCU and extract the zip file. This produces a folder named sp.
The user manual for this simulator, sp_doc.html, is included in this folder. It is strongly suggested that you read through this documentation describing how the simulator operates prior to beginning the following exercises.
Exercise Tasks – Part I.
Perform the following steps using the starving philosophers simulator
In the sp directory, execute ./runsp (UNIX, Linux, Mac OS X) or runsp.bat (Windows.) This will start the starving philosophers simulator. This simulates the Dining Philosophers problem with 5 philosophers numbered 0 through 4 with Philosopher 0 (in the green box) to Philosopher 4 (in the light-blue box.) Each box illustrates the state of each philosopher with T for Thinking, H for Hungry, and E for Eating.
Click on the green button labeled Step Event in the second column from the left of the main window. This will start the simulator for a single event which involves transitioning philosophers between the Thinking, Hungry, and Eating states. It will take several seconds for this event to complete. After it has completed, two philosophers will have changed states.
Click the Step Event button again. After the event has completed, two philosophers will have changed states.
Click the Step Event button again. After the event has completed, two philosophers will have changed states.
Click the Step Event button again. After the event has completed, only one philosopher will have changed state.
Click the pink Quit button in the upper right-hand corner of the main window. This will terminate the simulator.
———————————————————————————————–
Questions
Answer the following questions after completing Steps 1-6 above.
1. What is the initial state of all five philosophers after completing Step 1?
a) H (Hungry)
b) T (Thinking)
c) E (Eating)
2. At most, how many philosophers may be able to eat at the same time?
a) 1
b) 5
c) 3
d) 2
3. Which of the following statements are true for the Dining Philosophers problem?
a) Philosopher 0 is Thinking, Philosopher 1 is Hungry, Philosopher 2 is Eating,
Philosopher 3 is Hungry, Philosopher 4 is Eating
b) Philosopher 0 is Eating, Philosopher 1 is Hungry, Philosopher 2 is Thinking,
Philosopher 3 is Hungry, Philosopher 4 is Eating
c) Philosopher 0 is Hungry, Philosopher 1 is Eating, Philosopher 2 is Eating,
Philosopher 3 is Thinking, Philosopher 4 is Hungry
d) Philosopher 0 is Thinking, Philosopher 1 is Thinking, Philosopher 2 is Eating,
Philosopher 3 is Eating, Philosopher 4 is Thinking
4. What two philosophers first attempted to eat after performing Step 2?
a) Philosopher 0 and Philosopher 4
b) Philosopher 1 and Philosopher 3
c) Philosopher 2 and Philosopher 4
d) None of the above
5. What states are Philosopher 1 and Philosopher 3 in after performing Step 3?
a) Thinking
b) Hungry
c) Eating
6. What state did Philosopher 2 transition to after performing Step 4?
a) Thinking
b) Hungry
c) Eating
7. What state did Philosopher 1 transition to after performing Step 4?
a) Thinking
b) Hungry
c) Eating
———————————————————————————————–
———————————————————————————————–
Exercise Tasks – Part II & Questions
The following activities will have you proceed through the simulator, paying careful attention to the different queues each philosopher uses as it the monitor synchronizes its eating and thinking.
Perform the following steps using the starving-philosophers simulator.
In the sp directory, execute ./runsp (UNIX, Linux, Mac OS X) or runsp.bat (Windows.) This will start the starving philosophers simulator.
Click the Step Event button.
Q1. What queue did Philosophers 2 and 4 first enter?
a) Entry queue
b) Wait queue
Q2. Which philosopher first acquires the lock?
a) Philosopher 2
b) Philosopher 4
Q3. Is it necessary for a Philosopher to first own the lock for the monitor before it can change its state?
a) Yes
b) No
Click the Step Event Button again. This sets Philosophers 1 and 3 to the Hungry state. Both Philosophers 1 and 3 have a box adjacent to them that is now colored.
Q4. What does this box represent?
a) The lock for the monitor
b) The condition variable associated with that philosopher
c) The entry queue
d) The wait queue
Q5. Is it necessary for a Philosopher to first own the lock for the monitor before its adjacent box can be colored?
a) Yes
b) No
Click the Step Event button again. This sets the state of Philosopher 2 to Thinking, and Philosopher 1 to Eating.
Q6. What queue did Philosopher 1 enter immediately after it was by Philosopher 2?
a) Entry queue
b) Wait queue
Q7. This algorithm does not prevent a philosopher from starvation — a situation whereby it is hungry but is never allowed to eat. Explain how starvation could occur.
——————————————————————————————-
Assessment
1%
~ This is the End of Lab 6 ~
Tags: alwaysopen, assignmenthelpaustralia, assignmenthelpmelbourne, assignmenthelpsydney, assignmenthelpwebsites, london, londonstudent, melbourne, myassignmenthelp, plagiarismfreework, studentassignmenthelp