Esempio n. 1
0
	static void _exec(executor* exec) {
		while (true) {
			TaskPtr task = exec->pull();
			if (task) {
				task->run();
				continue;
			}
			if (!exec->_running) {
				std::cout << "Finished running all task " << exec << std::endl;
				return;
			}
		};
	}
Esempio n. 2
0
  //----------------------------------------------------------------
  // TaskRunner::TPrivate::threadLoop
  //
  void
  TaskRunner::TPrivate::threadLoop()
  {
    std::list<TaskPtr> next;
    Task::TimePoint next_time_point;

    while (true)
    {
      // grab the next set of tasks:
      {
        boost::unique_lock<boost::mutex> lock(mutex_);
        while (tasks_.empty())
        {
          // sleep until there is at least one task in the queue:
          cond_.wait(lock);
          boost::this_thread::interruption_point();
        }

        ready(tasks_, next, next_time_point);
      }

      while (!next.empty())
      {
        boost::this_thread::interruption_point();
        TaskPtr task = next.front();
        next.pop_front();
        task->run();
      }

      Task::TimePoint now = boost::chrono::steady_clock::now();
      if (now < next_time_point)
      {
        boost::chrono::nanoseconds ns = next_time_point - now;
        boost::this_thread::sleep_for(ns);
      }
    }
  }