/*
If the result indicates that we have outstanding tasks to do,
go ahead and run them in this thread.
966699
private void runDelegatedTasks(SSLEngine engine) throws Exception {

            Runnable runnable;
            while ((runnable = engine.getDelegatedTask()) != null) {
                logger.debug("\trunning delegated task...");
                runnable.run();
            }
            SSLEngineResult.HandshakeStatus hsStatus =
                    engine.getHandshakeStatus();
            if (hsStatus == SSLEngineResult.HandshakeStatus.NEED_TASK) {
                throw new Exception(
                        "handshake shouldn't need additional tasks");
            }
            logger.debug("\tnew HandshakeStatus: " + hsStatus);
    }
1320572
function done() {
        var arg = errors.length ? errors : null
        --pending || process.nextTick(callback, arg)
    }
1090028
def do_work
      done = false

      while not done
        queue_runner(@concurrency, @delay, @retry_count, @progress)

        if @interactive and @verify
          done = verify_results(@group)
          # a retry means we are not done yet.
          done = false if done == 'retry'
        else
          done = true
        end
      end

      if not @verify
        failed_workers, results_display = get_results(group)
        exit 1 if failed_workers.size > 0
      end

      puts 'chimp run complete'
    end
1253923
protected boolean setResult(Object result) {
        for (; ; ) {
            Object currentState = this.state;

            if (isDoneState(currentState)) {
                return false;
            }

            if (STATE.compareAndSet(this, currentState, result)) {
                done();
                notifyThreadsWaitingOnGet();
                runAsynchronous((ExecutionCallbackNode) currentState, result);
                break;
            }
        }
        return true;
    }
1373186
def run(self):
        
        while True:
            path, params = self.path_queue.get()
            errors = run(path, **params)
            self.result_queue.put(errors)
            self.path_queue.task_done()
149851
function done( error, results, info ) {
			error = error || null;
			results = results || null;
			info = info || null;
			clbk( error, results, info );
		}
1212517
@Override
  public void run() {
    try {
      if (tip.getTask().isMapTask()) {
        throw new RuntimeException("Only works for reducers!");
      }

      ReduceTask reduceTask = (ReduceTask) tip.getTask();

      LOG.info("MapperWaitThread started for reduce task " +
          reduceTask.getTaskID());
      int successfulMapCompletions = 0;
      int getFromEventId = 0;

      // Wait for the mappers in a loop
      while (successfulMapCompletions < reduceTask.getNumMaps()) {
        LOG.debug("Job: " + reduceTask.getJobID() + " ReduceTask: " +
            reduceTask.getTaskID() + " Got Successful Maps: " +
            successfulMapCompletions + "/" + reduceTask.getNumMaps());
        try {
          // This gets whether the mappers finished and also the location of the
          // output
          MapTaskCompletionEventsUpdate updates =
              umbilicalProtocol.getMapCompletionEvents(reduceTask.getJobID(), getFromEventId,
                  MAX_EVENTS_TO_FETCH, reduceTask.getTaskID());
          TaskCompletionEvent [] completionEvents =
              updates.getMapTaskCompletionEvents();

          if (updates.shouldReset()) {
            getFromEventId = 0;
            successfulMapCompletions = 0;
          }

          // Increment to get the next set of updates
          LOG.debug("Job: " + reduceTask.getJobID() + " ReduceTask: " +
              reduceTask.getTaskID() + " Got " +
              completionEvents.length + " map task " +
              " completion events");

          getFromEventId += completionEvents.length;

          // Tally up all the successful maps
          for(TaskCompletionEvent t : completionEvents) {
            if (t.getTaskStatus() == TaskCompletionEvent.Status.SUCCEEDED) {
              successfulMapCompletions++;
            }
          }

          // Update the progress of the threads so that they don't get killed
          // for inactivity
          umbilicalProtocol.statusUpdate(tip.getTask().getTaskID(), tip.getStatus());
          // If the thread were interrupted, then it means that we need to stop
          // as the task was killed
          if (Thread.interrupted()) {
            throw new InterruptedException("Generated in loop");
          }
          if (successfulMapCompletions % MAX_EVENTS_TO_FETCH == 0) {
            Thread.sleep(SLEEP_TIME);
          }

        } catch (IOException e) {
          LOG.error("Got an exception while getting map completion events", e);
        } catch (InterruptedException e) {
          LOG.debug("Got an interrupted exception while waiting for mappers  " +
              "for " + tip.getTask().getTaskID() + " job " +
              tip.getTask().getJobID());
          return;
        }
      }

      // All the mappers are done, so we can finish the reduce task
      LOG.info("Job: " + reduceTask.getJobID() + " ReduceTask: " +
          reduceTask.getTaskID() + " All maps finished, adding to task to " +
          "finish");
      taskRunner.addTipToFinish(tip, umbilicalProtocol);
    } finally {
      LOG.info("Exiting mapper wait thread " +
          "for " + tip.getTask().getTaskID() + " job " +
          tip.getTask().getJobID());
    }
  }
1189891
@Override
    @FFDCIgnore(Throwable.class)
    public void run() {
        Future<R> result = null;
        Throwable thrownException = null;

        try {
            ArrayList<ThreadContext> contextAppliedToThread = null;
            if (this.threadContext != null) {
                //apply the JEE contexts to the thread before calling the inner task
                contextAppliedToThread = this.threadContext.taskStarting();
            }
            try {
                result = innerTask.call();
            } finally {
                if (contextAppliedToThread != null) {
                    //remove the JEE contexts again since the thread will be re-used
                    this.threadContext.taskStopping(contextAppliedToThread);
                }
            }
        } catch (Throwable e) {
            if (e instanceof com.ibm.ws.microprofile.faulttolerance.spi.ExecutionException) {
                thrownException = e.getCause();
            } else {
                thrownException = e;
            }
        } finally {
            // We've finished running and caught any exceptions that occurred, now store the result in the resultFuture
            // If abort() has already been called then the result future will already be completed and the result (or exception) here is discarded.
            if (thrownException == null) {
                resultFuture.complete(result);
            } else {
                resultFuture.completeExceptionally(thrownException);
            }
        }
    }
601229
void execute() {
    boolean scheduleTaskRunner = false;
    synchronized (this) {
      if (!isThreadScheduled) {
        isThreadScheduled = true;
        scheduleTaskRunner = true;
      }
    }
    if (scheduleTaskRunner) {
      try {
        executor.execute(this);
      } catch (RuntimeException e) {
        // reset state in case of an error so that later calls to execute will actually do something
        synchronized (this) {
          isThreadScheduled = false;
        }
        // Log it and keep going.
        logger.log(
            Level.SEVERE,
            "Exception while running callbacks for " + listener + " on " + executor, 
            e);
        throw e;
      }
    }
  }
658624
def perform
      unless @threads.any? { |t| t.alive? }
        @values.start!
        @size.times do
          @threads << Thread.new do
            while job = @queue.pop
              if job == :END_OF_WORK
                break
              else
                @values.push *job[1], &job[0]
              end
            end
          end
        end
      end
    end
1088647
@Override
    public void finish() {
        if (started.get() && !finished.getAndSet(true)) {
            waitUntilFinished();
            super.finish();
            // recreate thread (don't start) for processor reuse
            createProcessorThread();
            clearQueues();
            started.set(false);
        }
    }
148946
public void runPendingTasks() {
        try {
            loop.runTasks();
        } catch (Exception e) {
            recordException(e);
        }

        try {
            loop.runScheduledTasks();
        } catch (Exception e) {
            recordException(e);
        }
    }
547700
public void run() {

		if (!initProxy()) {
			// Check if we have been aborted
			if (mode != OK_MODE)
				return;
			if (net_thread != Thread.currentThread())
				return;

			mode = COMMAND_MODE;
			warning_label.setText("Look up failed.");
			warning_label.invalidate();
			return;
		}

		// System.out.println("Done!");
		while (!warning_dialog.isShowing())
			; /* do nothing */
		;

		warning_dialog.dispose();
		// dispose(); //End Dialog
	}
923728
public void requestProcessed (Object result)
    {
        @SuppressWarnings("unchecked") V value = (V)result;
        _sync.innerSet(value);
    }
619906
void runAsync() {
        // Determine if a task is running. If so, record the fact we want to have it run again, otherwise reserve our spot.
        synchronized (this) {
            Exceptions.checkNotClosed(this.closed, this);
            if (this.running) {
                this.runAgain = true;
                return;
            }

            this.running = true;
        }

        // Execute the task.
        runInternal();
    }
558977
private void run(final RunNode current) {
        try {
            current.runnable.run();
        } catch (final Throwable thrown) {
            reportFailure(Thread.currentThread(), thrown);
        }
    }
771014
public <T> void notifySuccess(final Callback<T> callback, final T result) {
    invokeLater(new Runnable() {
      public void run() {
        callback.onSuccess(result);
      }
    });
  }