wake enough threads to process the tasks
324816
private void wakeThreads(int count)
  {
    while (true) {
      int taskCount = Math.max(0, _taskCount.get());
    
      int spinIdleCount = _spinIdleCount.get();
      long threadWakeHead = _threadWakeHead.get();
      long threadWakeTail = _threadWakeTail.get();
    
      long threadCount = spinIdleCount + threadWakeHead - threadWakeTail;
      
      if (taskCount <= threadCount) {
        return;
      }
      
      if (count <= threadCount) {
        return;
      }
      
      ThreadAmp thread = _idleThreadRing.poll();
      
      if (thread == null) {
        return;
      }
      
      if (_threadWakeHead.compareAndSet(threadWakeHead, threadWakeHead + 1)) {
        thread.setWakeThread();
        LockSupport.unpark(thread);
      }
      else {
        // avoid duplicate wake
        _idleThreadRing.offer(thread);
      }
    }
  }
540595
def wakeup
      raise NotRunning.new unless running?
      if(@sleeper.waiters > 0)
        @sleeper.signal
      else
        @timer_thread.wakeup if @timer_thread.alive? && @timer_thread.stop?
      end
    end
5135
void processBatchWaitTasks() {
		Channel channel = context.registry.getChannelOrSystem(Model.CHANNEL_BATCH); // channel TedBW or TedSS
		int maxTask = context.taskManager.calcChannelBufferFree(channel);
		Map<String, Integer> channelSizes = new HashMap<String, Integer>();
		channelSizes.put(Model.CHANNEL_BATCH, maxTask);
		List<TaskRec> batches = context.tedDao.reserveTaskPortion(channelSizes);
		if (batches.isEmpty())
			return;

		for (final TaskRec batchTask : batches) {
			channel.workers.execute(new TedRunnable(batchTask) {
				@Override
				public void run() {
					processBatchWaitTask(batchTask);
				}
			});
		}
	}
46392
def start(self):
        
        if not self._done_event.is_set():
            # Stop event not set: we're running
            return

        # Clear the stop event
        self._done_event.clear()

        # Compute the number of threads to start to handle pending tasks
        nb_pending_tasks = self._queue.qsize()
        if nb_pending_tasks > self._max_threads:
            nb_threads = self._max_threads
            nb_pending_tasks = self._max_threads
        elif nb_pending_tasks < self._min_threads:
            nb_threads = self._min_threads
        else:
            nb_threads = nb_pending_tasks

        # Create the threads
        for _ in range(nb_pending_tasks):
            self.__nb_pending_task += 1
            self.__start_thread()
        for _ in range(nb_threads - nb_pending_tasks):
            self.__start_thread()
1219191
public static void main(String[] args) throws Exception {
        while( true ) {
           Thread.sleep(1000*60*5);
           System.out.println("Test wakeup");
        }
    }
1018064
def start_tasks(self):
        
        while self.tasks_at_once > len(self.pending_results) and self._has_more_tasks():
            task, parent_result = self.tasks.popleft()
            self.execute_task(task, parent_result)
289584
def run(self):
        
        self.main_task.thread.start()
        self.main_task.thread.join()
381974
def start_threads(self, n_threads):
    
    if n_threads == len(self._threads):
      return self
    
    # Terminate all previous tasks with the existing
    # event object, then create a new one for the next
    # generation of threads. The old object will hang
    # around in memory until the threads actually terminate
    # after another iteration.
    self._terminate.set()
    self._terminate = threading.Event()

    threads = []

    for _ in range(n_threads):
      worker = threading.Thread(
        target=self._consume_queue, 
        args=(self._terminate,)
      )
      worker.daemon = True
      worker.start()
      threads.append(worker)

    self._threads = tuple(threads)
    return self
760434
private synchronized void mainLoop() {
        for (Task task: taskDao.listTasks()) {
            if (task.getState().equals(Task.STARTING)) {
                startTask(task);
            } else if (task.getState().equals(Task.PAUSING)) {
                pauseTask(task);
            } else if (task.getState().equals(Task.RESUMING)) {
                resumeTask(task);
            } else if (task.getState().equals(Task.CANCELING)) {
                cancelTask(task);
            }
        }
        try {
            wait(POLL_SECONDS * 1000);
        } catch (InterruptedException e) {
        }
    }
1290795
def Run(self):
    """"""
    for thread in itervalues(self._threads):
      thread.start()
    logging.info(START_STRING)

    while True:
      dead_threads = [
          tn for (tn, t) in iteritems(self._threads) if not t.isAlive()
      ]
      if dead_threads:
        raise FatalError(
            "These threads are dead: %r. Shutting down..." % dead_threads)
      time.sleep(10)
715544
def run(self):
        '''
        
        '''
        self.thread = Thread(target=self.__processQueue)
        self.thread.start()
1287785
private void manageTasks() {
        setHostAddress();
        while (!m_bShutdown) {
            checkAllTasks();
            checkForDeadTasks();
            try {
                Thread.sleep(SLEEP_TIME_MILLIS);
            } catch (InterruptedException e) {
            }
        }
        m_executor.shutdown();
    }
213295
def start( self ):
        
        if ( self.localThreadingEnabled() and self.globalThreadingEnabled() ):
            super(XThread, self).start()
        else:
            self.run()
            self.finished.emit()
294902
def __thread_started(self):
		
		if self.__task is None:
			raise RuntimeError('Unable to start thread without "start" method call')
		self.__task.start()
		self.__task.start_event().wait(self.__scheduled_task_startup_timeout__)
1007631
def run(self):
        """"""
        event_handler = Handler()
        threads = []
        paths = [os.path.join(cwd, "content"), os.path.join(cwd, "templates")]

        for i in paths:
            targetPath = str(i)
            self.observer.schedule(event_handler, targetPath, recursive=True)
            threads.append(self.observer)

        self.observer.start()

        try:
            while True:
                time.sleep(5)
        except:
            self.observer.stop()
            print("\nObserver stopped.")

        self.observer.join()
748505
function() {
    firstTaskTimeout = clearTimeout(firstTaskTimeout);
    const task = taskQueue.shift();

    if (task) {
      const conn = idleConnections.shift();
      if (conn) {
        activeConnections[conn.threadId] = conn;
        resetTimeoutToNextTask();
        processTask(conn, task.sql, task.values, task.isBatch)
          .then(task.resolve)
          .catch(task.reject);
      } else {
        taskQueue.unshift(task);
      }
    }
  }
627252
def _run(cls):
        """"""
        if cls._thread:
            with cls._lock:
                # First run: execute each task once to get it started
                for task in cls.tasks:
                    cls._execute_task(task)
                cls.tasks.sort()
                cls._last_execution = time.time()

        while cls._thread:
            with cls._lock:
                if cls.tasks:
                    for task in cls.tasks:
                        if task.next_execution - cls._last_execution < 0.5:
                            cls._execute_task(task)
                        else:
                            break
                    cls.tasks.sort()
                    cls._last_execution = time.time()
                    cls._sleep_delay = cls.tasks[0].next_execution - cls._last_execution

                else:
                    cls._sleep_delay = 1

                sleep_delay = max(0.1, cls._sleep_delay)

            # Don't hold cls._lock while sleeping, sleep delay should be 1 second when no tasks are present
            time.sleep(sleep_delay)