You are to implement the assign3_Waiter
class as a monitor, with public
methods as follows:
assign3_Waiter(int Num)
-- Constructor. Num
is the number of philosophers at the table.void request(int seat)
-- The philosopher at position
seat
(0 ≤ seat
< Num
) request
permission to eat. This should block until it is safe for him to eat.void done(int seat)
-- The philosopher at position
seat
calls this to indicate that he is finished eating.Be sure to specify the monitor invariant in comments in your code.
Your solution should avoid starvation without relying on the fairness of
the monitor locks.
Submit assign3_Waiter.java
Don't include main
-- I'll make my own.
The students drink at varying rates, so, in the interest of fairness, they instruct the bartender to keep track of the number of glasses of beer served to each student, and, when more than one student is waiting to be served, to serve the student who has had the fewest glasses.
The more astute among the students (i.e., those who have taken concurrent programming), recognize this as a conditional synchronization problem and set out to simulate the interaction in a Java program. They model the students and runner as in Student.java, and Runner.java.
Implement the assign3_Bartender
class using Java monitors. The
class must have public methods as follows:
assign3_Bartender(int kegSize, int numStudents)
-- constructor.
The arguments are the number of glasses in a keg and the number of drinking
students.void getBeer(int id)
--
called by the students and blocks until the student's glass is filled,
andvoid installNewKeg()
-- called by the runner and blocks
until the old keg is consumed and the new keg is installed.Be sure to specify the monitor invariant in comments in your code. Submit assign3_Bartender.java. Don't include a main -- I'll put yours and mine together to make my own party.
Last modified: Tue 2004.03.09 at 08:57 NST by Dennis Peters