Logo Search packages:      
Sourcecode: scala version File versions  Download package

synchronized void scala::actors::FJTaskRunnerGroup::checkActive ( FJTaskRunner  t,
long  scans 
) [inline]

Set active status of thread t to false, and then wait until: (a) there is a task in the entry queue, or (b) other threads are active, or (c) the current thread is interrupted. Upon return, it is not certain that there will be work available. The thread must itself check.

The main underlying reason for these mechanics is that threads do not signal each other when they add elements to their queues. (This would add to task overhead, reduce locality. and increase contention.) So we must rely on a tamed form of polling. However, tasks inserted into the entry queue do result in signals, so tasks can wait on these if all of them are otherwise idle.

Implements scala::actors::IFJTaskRunnerGroup.

Definition at line 628 of file FJTaskRunnerGroup.java.

References activeCount, entryQueue, MAX_SLEEP_TIME, scala::actors::LinkedQueue::peek(), SCANS_PER_SLEEP, and setInactive().

                                                                   {

    setInactive(t);

    try {
      // if nothing available, do a hard wait
      if (activeCount == 0 && entryQueue.peek() == null) { 
        wait();
      }
      else { 
        // If there is possibly some work,
        // sleep for a while before rechecking 

        long msecs = scans / SCANS_PER_SLEEP;
        if (msecs > MAX_SLEEP_TIME) msecs = MAX_SLEEP_TIME;
        int nsecs = (msecs == 0) ? 1 : 0; // forces shortest possible sleep
        wait(msecs, nsecs);
      }
    }
    catch (InterruptedException ex) {
      notify(); // avoid lost notifies on interrupts
      Thread.currentThread().interrupt();
    }
  }


Generated by  Doxygen 1.6.0   Back to index