Exemple #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");
  }
 public void activate() {
   active = true;
   microphone.flush();
   speaker.flush();
   speaker.start();
   blocker.release();
   microphone.start();
   microphone.flush();
 }
Exemple #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
  }
 /**
  * This should be called whenever state has changed that might cause the agent to do something.
  */
 protected void stateChanged() {
   stateChange.release();
 }
 public void resume() {
   pause.release();
   isPaused = false;
   stateChanged();
 }
    /** @param f Future that finished. */
    private void signalTaskFinished(GridFuture<Object> f) {
      assert f != null;

      sem.release();
    }
 public void pickup() {
   pickup.release();
 }