private boolean moreToStart()
{
for( int i = 0; i < phils.length; i++ )
{
if( !phils[i].isAlive())
return true;
}
return false;
}
private int n;
private Philosopher[] phils;
private boolean[] chops;
private Random r;
private static final int maxPhils = 24; //最多哲学家数
private static final int maxEat = 4; //最多进餐时间
private static final int minEat = 1; //最少进餐时间
}
class Philosopher extends Thread
{
public Philosopher( DiningPhils HOST , int i )
{
host = HOST;
index = i;
}
public void setTimeSlice( int TS )
{
ts = TS;
}
public void setLeftChopstick( boolean flag )
{
host.setChopstick(index, flag);
}
public void setRightChopstick( boolean flag )
{
host.setChopstick((index + 1)% host.getCount() , flag);
}
private void releaseChopsticks()
{
setLeftChopstick(false);
setRightChopstick(false);
}
责任编辑:小草