예제 #1
0
  public void enterBarrier(int barrierNum, int threadNum) {

    if (!active) {
      throw new IllegalStateException(
          "Parallel Region is not active, unable to enter/escape a barrier");
    }

    if (log.isDebugEnabled()) {
      log.debug("OMP thread " + threadNum + " is entering barrier " + barrierNum);
    }

    if (barrierNum < 0) {
      throw new IllegalArgumentException("Barrier number must be >= 0");
    }

    if (threadNum < 0 || threadNum > team.length - 1) {
      throw new IllegalArgumentException(
          "Thread with number " + threadNum + " not registered in this region");
    }

    OMPThreadBarrier barrier;

    barrierLock.lock();
    try {
      barrier = barriers.get(barrierNum);
      if (barrier == null) {
        if (log.isDebugEnabled()) {
          log.debug("OMP thread " + threadNum + " is the first to enter barrier " + barrierNum);
        }
        barrier = new OMPThreadBarrier(team.length);
        barriers.put(barrierNum, barrier);
      }
    } finally {
      barrierLock.unlock();
    }

    // this Java thread will wait
    barrier.await(team[threadNum]);
  }
예제 #2
0
  public boolean escapeBarrier(int barrierNum, int threadNum) {

    if (!active) {
      throw new IllegalStateException(
          "Parallel Region is not active, unable to enter/escape a barrier");
    }

    if (barrierNum < 1) {
      throw new IllegalArgumentException("Barrier number must be > 0");
    }

    if (threadNum < 0 || threadNum > team.length - 1) {
      throw new IllegalArgumentException(
          "Thread with number " + threadNum + " not registered in this region");
    }

    OMPThreadBarrier barrier = barriers.get(barrierNum);
    if (barrier == null) {
      throw new IllegalArgumentException("No barrier with id " + barrierNum + " registered");
    }

    return barrier.release(threadNum);
  }