|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Process | +--Philosopher
A Philosopher is a process that thinks and eats. When a philosopher starts to eat, it must first get its left and right chopsticks.
Field Summary | |
static int |
EATING
EATING is the state constant for eating philosophers. |
static int |
HUNGRY
HUNGRY is the state constant for hungry philosophers. |
protected Philosopher |
left
left is the left neighbor of this philosopher. |
protected java.lang.String |
leftChopstick
leftChopstick is the name of the chopstick to the left of this philosopher. |
protected static Semaphore |
mutex
mutex is a mutual exclusion semaphore that is used by all philosophers when accessing philosopher state information. |
protected Semaphore |
permission
permission controls permission to eat for this philosopher. |
protected Philosopher |
right
right is the right neighbor of this philosopher. |
protected int |
state
state is the state of this philosopher: THINKING, HUNGRY, or EATING. |
static int |
THINKING
THINKING is the state constant for thinking philosophers. |
Constructor Summary | |
Philosopher(java.lang.String nm,
double t)
new Philosopher(nm, t) returns a new philosopher and starts executing its run method in a new thread. |
Method Summary | |
protected void |
eat()
eat() simulates eating for this philosopher. |
java.lang.String |
getLeftChopstick()
phil.getLeftChopstick(p) returns the name of the chopstick to the left of phil. |
static void |
go()
Philosopher.go() allows philosophers to access their state information. |
protected void |
pickUpChopsticks()
pickUpChopsticks() simulates picking up chopsticks for this philosopher. |
protected void |
putDownChopsticks()
putDownChopsticks() simulates putting down chopsticks for this philosopher. |
void |
setLeftNeighbor(Philosopher p)
phil.setLeftNeighbor(p) makes p the left neighbor of phil and makes phil the right neighbor of p. |
protected void |
step()
phil.step() simulates a think and eat cycle for phil. |
protected void |
think()
think() simulates thinking for this philosopher. |
protected static void |
tryToGrantPermission(Philosopher p)
tryToGrantPermission(p) attempts to grant permission for p to eat. |
Methods inherited from class Process |
run, setSimulationTime, toString, twiddle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int THINKING
public static final int HUNGRY
public static final int EATING
protected int state
protected Philosopher left
protected Philosopher right
protected Semaphore permission
protected java.lang.String leftChopstick
protected static Semaphore mutex
Constructor Detail |
public Philosopher(java.lang.String nm, double t)
Method Detail |
public void setLeftNeighbor(Philosopher p)
public java.lang.String getLeftChopstick()
protected void step()
step
in class Process
protected void think()
protected void pickUpChopsticks()
protected void eat()
protected void putDownChopsticks()
protected static void tryToGrantPermission(Philosopher p)
public static void go()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |