本文整理汇总了C++中TaskPtr::run方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskPtr::run方法的具体用法?C++ TaskPtr::run怎么用?C++ TaskPtr::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskPtr
的用法示例。
在下文中一共展示了TaskPtr::run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _exec
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;
}
};
}
示例2: while
//----------------------------------------------------------------
// 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);
}
}
}