本文整理汇总了C++中WorkQueue::schedule方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkQueue::schedule方法的具体用法?C++ WorkQueue::schedule怎么用?C++ WorkQueue::schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkQueue
的用法示例。
在下文中一共展示了WorkQueue::schedule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tst_schedulBatchAndWait
void tst_schedulBatchAndWait()
{
GLOBAL_COUNTER = 0;
WorkQueue queue;
const int COUNT = 5;
std::vector<shared_ptr<WorkQueue::Job> > jobs;
// Schedule a couple of jobs..
for (int i=0; i<COUNT; ++i) {
jobs.push_back(shared_ptr<WorkQueue::Job>(new OneJob(i)));
queue.schedule(jobs.back());
}
// Wait for the very last one...
jobs.back()->waitForCompletion();
for (int i=0; i<COUNT; ++i) {
OneJob *j = static_cast<OneJob *>(jobs.at(i).get());
// Job should have completed.
check_true(j->hasCompleted());
// This will guarantee that the jobs have been completed in the right
// order..
check_equal(j->runId, j->jobId);
}
cout << __FUNCTION__ << ": ok" << endl;
}
示例2: tst_runOneJob
void tst_runOneJob()
{
GLOBAL_COUNTER = 1;
WorkQueue queue;
shared_ptr<WorkQueue::Job> job(new OneJob(1));
check_true(!job->hasCompleted());
check_equal(static_cast<OneJob *>(job.get())->runId, -1);
queue.schedule(job);
// Spin a while loop, waiting 1 ms at a time, to see if the job completes
// on its own. If we're still spinning after 10000 iterations, emit a warning
// that the thing is probably locked up
int counter = 0;
while (!job->hasCompleted()) {
this_thread::sleep_for(std::chrono::milliseconds(1));
++counter;
if (counter > 10000) {
cout << __FUNCTION__ << ": has with all likelyhood timed out, assuming failure!" << endl;
check_true(false);
}
}
if (counter == 0) {
cout << " - job seems to have completed without any delay.. This is suspicious.." << endl;
return;
}
// The runId should be the one we set up above, namely 1, as this is the
// only job executing at present.
check_equal(static_cast<OneJob *>(job.get())->runId, 1);
cout << __FUNCTION__ << ": ok" << endl;
}