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


C++ ThreadPool::addJob方法代码示例

本文整理汇总了C++中ThreadPool::addJob方法的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPool::addJob方法的具体用法?C++ ThreadPool::addJob怎么用?C++ ThreadPool::addJob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadPool的用法示例。


在下文中一共展示了ThreadPool::addJob方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: resolve

void DependencyTree::resolve()
{
  resolvedList.clear();
  resolvingList.clear();
  ThreadPool threadPool;
  for (;;)
  {
    Resolvers resolvers;
    for (auto &&target : tree)
      resolve(target.first, resolvers);

    if (resolvers.empty() && resolvingList.empty() && threadPool.empty())
      return;

    std::string target;
    Resolver *resolver;
    time_t newestModificationTime;

    for (auto &&r : resolvers)
    {
      std::tie(target, resolver, newestModificationTime) = r;
      if (!isFileExist(target))
      {
        resolvingList.insert(target);
        threadPool.addJob([resolver]() { resolver->exec(); },
                          [this, target]() {
                            resolvingList.erase(target);
                            resolvedList.insert(target);
                          });
        continue;
      }
      auto time = getFileModification(target);
      if (time < newestModificationTime)
      {
        resolvingList.insert(target);
        threadPool.addJob([resolver]() { resolver->exec(); },
                          [this, target]() {
                            resolvingList.erase(target);
                            resolvedList.insert(target);
                          });
      }
      else
        resolvedList.insert(target);
    }
    threadPool.waitForOne();
  }
}
开发者ID:antonte,项目名称:coddle,代码行数:47,代码来源:dependency_tree.cpp

示例2: MatchDocument

ErrorCode MatchDocument(DocID doc_id, const char* doc_str) {

    // Uncomment if you're parallelising start query.
    /*tPool.barrierAll(START);
    pthread_mutex_lock(&querySort);
    if(sortQueries){
    	sortQueries = false;
    	sort(queries.begin(), queries.end(), queryCompare);
    }
    pthread_mutex_unlock(&querySort);*/

    static int n=0;

    char *icy = (char*)malloc(sizeof(char) * MAX_DOC_LENGTH);
    strcpy(icy, doc_str);

    int n1=queries.size();

    if(n!=n1) {

        for(int i=n; i<n1; i++) {
            Query_st x;

            x.query=queries[i];

            for(char *ph = strtok(queries[i].str," "); ph != NULL; ph=strtok(NULL," "))
                x.tokens.push_back(ph);

            query_hash.push_back(x);
            n=n1;
        }
    }

    MatchJob * job = new MatchJob(MatchDocument2, doc_id, icy);
    tPool.addJob(job);

    return EC_SUCCESS;
}
开发者ID:pkyriacou,项目名称:SIGMOD_2013,代码行数:38,代码来源:core.cpp

示例3: writeProjects

void ProjectSaver::writeProjects (const OwnedArray<LibraryModule>& modules, const String& specifiedExporterToSave, bool isCommandLineApp)
{
    ThreadPool threadPool;

    // keep a copy of the basic generated files group, as each exporter may modify it.
    auto originalGeneratedGroup = generatedFilesGroup.state.createCopy();

    CLionProjectExporter* clionExporter = nullptr;
    OwnedArray<ProjectExporter> exporters;

    try
    {
        for (Project::ExporterIterator exp (project); exp.next();)
        {
            if (specifiedExporterToSave.isNotEmpty() && exp->getName() != specifiedExporterToSave)
                continue;

            auto* exporter = exporters.add (exp.exporter.release());

            exporter->initialiseDependencyPathValues();

            if (exporter->getTargetFolder().createDirectory())
            {
                if (exporter->isCLion())
                {
                    clionExporter = dynamic_cast<CLionProjectExporter*> (exporter);
                }
                else
                {
                    exporter->copyMainGroupFromProject();
                    exporter->settings = exporter->settings.createCopy();

                    exporter->addToExtraSearchPaths (RelativePath ("JuceLibraryCode", RelativePath::projectFolder));

                    generatedFilesGroup.state = originalGeneratedGroup.createCopy();
                    exporter->addSettingsForProjectType (project.getProjectType());

                    for (auto& module: modules)
                        module->addSettingsForModuleToExporter (*exporter, *this);

                    generatedFilesGroup.sortAlphabetically (true, true);
                    exporter->getAllGroups().add (generatedFilesGroup);
                }

                if (isCommandLineApp)
                    saveExporter (exporter, modules);
                else
                    threadPool.addJob (new ExporterJob (*this, exporter, modules), true);
            }
            else
            {
                addError ("Can't create folder: " + exporter->getTargetFolder().getFullPathName());
            }
        }
    }
    catch (ProjectExporter::SaveError& saveError)
    {
        addError (saveError.message);
    }

    if (! isCommandLineApp)
        while (threadPool.getNumJobs() > 0)
            Thread::sleep (10);

    if (clionExporter != nullptr)
    {
        for (auto* exporter : exporters)
            clionExporter->writeCMakeListsExporterSection (exporter);

        std::cout << "Finished saving: " << clionExporter->getName() << std::endl;
    }
}
开发者ID:julianstorer,项目名称:JUCE,代码行数:72,代码来源:jucer_ProjectSaver.cpp


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