示例#1
0
  public void run() {
    pr.println("Writer " + id + " is trying to write");
    S.semWait(); // semWait on S, see if allowed in critical section
    pr.println("Writer " + id + " is starting to write");

    try {
      sleep((long) (Math.random() * 1000)); // "writing"
    } catch (InterruptedException e) {
    }
    ;
    pr.println("Writer " + id + " is done writing");

    S.semSignal(); // semSignal on S, done writing critical section
    pr.println("Writer " + id + " is wrapping things up");
  }
示例#2
0
 public void activate() {
   active = true;
   microphone.flush();
   speaker.flush();
   speaker.start();
   blocker.release();
   microphone.start();
   microphone.flush();
 }
示例#3
0
  public void run() {

    pr.println("Reader " + id + " trying to get into CR");

    mutex.semWait(); // semWait on mutex, only one reader can adjust count
    readCount++;

    if (readCount == 1) S.semWait(); // semWait on S

    mutex.semSignal(); // semSignal on mutex

    pr.println("Reader " + id + " is reading");

    try {
      sleep((long) (Math.random() * 1000));

    } catch (InterruptedException e) {
    }
    ;

    pr.println("Reader " + id + " is done reading");
    mutex.semWait();
    readCount--;
    if (readCount == 0) S.semSignal(); // semSignal on S
    mutex.semSignal(); // semSignal on mutex
  }
示例#4
0
 /**
  * This should be called whenever state has changed that might cause the agent to do something.
  */
 protected void stateChanged() {
   stateChange.release();
 }
示例#5
0
 public void resume() {
   pause.release();
   isPaused = false;
   stateChanged();
 }
示例#6
0
    /** @param f Future that finished. */
    private void signalTaskFinished(GridFuture<Object> f) {
      assert f != null;

      sem.release();
    }
示例#7
0
 public void pickup() {
   pickup.release();
 }