You are to implement the
assign3_Waiter class as a monitor, with public
methods as follows:
assign3_Waiter(int Num)-- Constructor.
Numis the number of philosophers at the table.
void request(int seat)-- The philosopher at position
Num) request permission to eat. This should block until it is safe for him to eat.
void done(int seat)-- The philosopher at position
seatcalls 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.
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.
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, and
void 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