当前位置: 首页>>代码示例>>C++>>正文


C++ WorkQueue::schedule方法代码示例

本文整理汇总了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;
}
开发者ID:sletta,项目名称:rengine,代码行数:31,代码来源:tst_workqueue.cpp

示例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;
}
开发者ID:sletta,项目名称:rengine,代码行数:36,代码来源:tst_workqueue.cpp


注:本文中的WorkQueue::schedule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。