Exemplo n.º 1
0
  /**
   * Atomically release the associated lock and go to sleep on this condition variable until another
   * thread wakes it using <tt>wake()</tt>. The current thread must hold the associated lock. The
   * thread will automatically reacquire the lock before <tt>sleep()</tt> returns.
   *
   * <p>This implementation uses semaphores to implement this, by allocating a semaphore for each
   * waiting thread. The waker will <tt>V()</tt> this semaphore, so thre is no chance the sleeper
   * will miss the wake-up, even though the lock is released before caling <tt>P()</tt>.
   */
  public void sleep() {
    Lib.assertTrue(conditionLock.isHeldByCurrentThread());

    Semaphore waiter = new Semaphore(0);
    waitQueue.add(waiter);

    conditionLock.release();
    waiter.P();
    conditionLock.acquire();
  }
Exemplo n.º 2
0
 public void run() {
   while (true) {
     matcher_wait.P();
     try {
       System.out.println("Matcher => run() metodu...");
       runMatcher();
     } catch (Exception e) {
       System.out.println("Matcher calisirken hata olustu!");
     }
   }
 }
Exemplo n.º 3
0
  public void acquire(XThread requester) {
    if (logger.isDebugEnabled()) {
      logger.debug("acquire::" + name + "(XThread) - start");
    }

    sem.P(requester);
    owner = requester;

    if (logger.isDebugEnabled()) {
      logger.debug("acquire::" + name + "(XThread) - end");
    }
  }
Exemplo n.º 4
0
  /**
   * Called by the parent thread to process work requests posted for it. This method does not return
   * unless there are no further pending requests to be processed AND all child threads have
   * terminated. If there are no requests to be processed, but some child threads are still active,
   * then the parent thread will block within this method awaiting further requests (for example,
   * those that will eventually result from the termination of the currently active child threads).
   *
   * @throws IllegalStateException if the calling thread is not registered as the parent thread for
   *     this TaskManager.
   */
  public void processRequests() throws IllegalStateException {
    try {
      // Don't let any threads except Parent thread execute this method
      if (!NachosThread.currentThread().name.equals(mParentThreadName)) return;
      // Main thread waits till all requests have been served / all worker threads have been
      // finished
      while (true) {
        // Run the post doInBackground actions such as onCompletion and onCancellation
        for (Runnable response : mResponses) {
          response.run();
        }
        if (mResponses.size() == mThreadCounter) {
          break;
        } else {
          mSemaphoreForFirstThread.P();
        }
      }
    } catch (Exception ex) {

    }
  }
Exemplo n.º 5
0
 /**
  * Posts a request for a Runnable to be executed by the parent thread.
  * Such a Runnable might consist of a call to <CODE>onCompletion()</CODE>
  * or <CODE>onCancellation() associated with the completion of a task
  * being performed by a child thread, or it might consist of
  * completely unrelated work (such as responding to user interface
  * events) for the parent thread to perform.
  *
  * NOTE: This method should be safely callable by any thread.
  *
  * @param runnable  Runnable to be executed by the parent thread.
  */
 public void postRequest(Runnable runnable) {
   mPostRequestsSemaphore.P();
   mRequests.add(runnable);
   mPostRequestsSemaphore.V();
 }