Java解哲学家就餐问题
来源:优易学  2011-9-12 12:11:05   【优易学:中国教育考试门户网】   资料下载   IT书店

  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);
  }

上一页  [1] [2] [3] [4] [5] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训