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


C++ future::valid方法代码示例

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


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

示例1: StopHTTPServer

void StopHTTPServer()
{
    LogPrint(BCLog::HTTP, "Stopping HTTP server\n");
    if (workQueue) {
        LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n");
        workQueue->WaitExit();
        delete workQueue;
        workQueue = nullptr;
    }
    if (eventBase) {
        LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
        // Give event loop a few seconds to exit (to send back last RPC responses), then break it
        // Before this was solved with event_base_loopexit, but that didn't work as expected in
        // at least libevent 2.0.21 and always introduced a delay. In libevent
        // master that appears to be solved, so in the future that solution
        // could be used again (if desirable).
        // (see discussion in https://github.com/bitcoin/bitcoin/pull/6990)
        if (threadResult.valid() && threadResult.wait_for(std::chrono::milliseconds(2000)) == std::future_status::timeout) {
            LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
            event_base_loopbreak(eventBase);
        }
        threadHTTP.join();
    }
    if (eventHTTP) {
        evhttp_free(eventHTTP);
        eventHTTP = 0;
    }
    if (eventBase) {
        event_base_free(eventBase);
        eventBase = 0;
    }
    LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
}
开发者ID:Crinklebine,项目名称:bitcoin,代码行数:33,代码来源:httpserver.cpp

示例2: close

    /**
     * Close the task. This will raise in this thread any exception the
     * task generated in the other thread. Calling this function is
     * optional, because the destructor will also call this function.
     * But because it can throw an exception, it is better to call it
     * explicitly.
     */
    void close() {
        // If an exception happened in the task, re-throw
        // it in this thread. This will block if the task
        // isn't finished.
        if (m_future.valid()) {
            m_future.get();
        }

        // Make sure task is done.
        if (m_thread.joinable()) {
            m_thread.join();
        }
    }
开发者ID:natsumiirimura,项目名称:libosmium,代码行数:20,代码来源:checked_task.hpp

示例3: on_update

    void on_update(const UpdateEvent & e) override
    {
        // Around 60 fps
        if (fixedTimer.milliseconds().count() >= 16 && turret.fired)
        {
            float timestep_ms = fixedTimer.milliseconds().count() / 1000.f;
            turret.projectile.fixed_update(timestep_ms);
            std::cout << timestep_ms << std::endl;
            //std::cout << turret.projectile.p.position << std::endl;
            fixedTimer.reset();
        }

        cameraController.update(e.timestep_ms);
        time += e.timestep_ms;
        shaderMonitor.handle_recompile();

        // If a new mesh is ready, retrieve it
        if (pointerFuture.valid())
        {
            auto status = pointerFuture.wait_for(std::chrono::seconds(0));
            if (status != std::future_status::timeout)
            {
                auto m = pointerFuture.get();
                supershape = m;
                supershape.pose.position = {0, 2, -2};
                pointerFuture = {};
            }
        }

        // If we don't currently have a background task, begin working on the next mesh
        if (!pointerFuture.valid() && regeneratePointer)
        {
            pointerFuture = std::async([]() {
                return make_supershape_3d(16, ssM, ssN1, ssN2, ssN3);
            });
        }
    }
开发者ID:ddiakopoulos,项目名称:sandbox,代码行数:37,代码来源:geometric_algo_dev.hpp

示例4: io_error

            /**
             * Get the header data from the file.
             *
             * @returns Header.
             * @throws Some form of osmium::io_error if there is an error.
             */
            osmium::io::Header header() {
                if (m_status == status::error) {
                    throw io_error("Can not get header from reader when in status 'error'");
                }

                try {
                    if (m_header_future.valid()) {
                        m_header = m_header_future.get();
                        if (m_read_which_entities == osmium::osm_entity_bits::nothing) {
                            m_status = status::eof;
                        }
                    }
                } catch (...) {
                    close();
                    m_status = status::error;
                    throw;
                }
                return m_header;
            }
开发者ID:7ute,项目名称:osrm-backend,代码行数:25,代码来源:reader.hpp

示例5: hook_post_step

  void hook_post_step()
  {
    parent_t::hook_post_step(); // includes output

    this->mem->barrier();

    if (this->rank == 0) 
    {
      // assuring previous async step finished ...
#if defined(STD_FUTURE_WORKS)
      if (
        params.async && 
        this->timestep != 0 && // ... but not in first timestep ...
        ((this->timestep - 1) % this->outfreq != 0) // ... and not after diag call
        //!((this->timestep-1) == 0 || ((this->timestep-1) % this->outfreq == 0 && (this->timestep-1) >= this->spinup)) // .. and not after diag
      ) {
        assert(ftr.valid());
        ftr.get();
      } else assert(!ftr.valid());
#endif

      // running synchronous stuff
      prtcls->step_sync(
        params.cloudph_opts,
        make_arrinfo(this->mem->advectee(ix::th)),
        make_arrinfo(this->mem->advectee(ix::rv))
      ); 

      // running asynchronous stuff
      {
        using libcloudphxx::lgrngn::particles_t;
        using libcloudphxx::lgrngn::CUDA;
        using libcloudphxx::lgrngn::multi_CUDA;

#if defined(STD_FUTURE_WORKS)
        if (params.async)
        {
          assert(!ftr.valid());

          if(params.backend == multi_CUDA)
            ftr = std::async(
              std::launch::async, 
              &particles_t<real_t, multi_CUDA>::step_async, 
              dynamic_cast<particles_t<real_t, multi_CUDA>*>(prtcls.get()),
              params.cloudph_opts
            );
          else if(params.backend == CUDA)
            ftr = std::async(
              std::launch::async, 
              &particles_t<real_t, CUDA>::step_async, 
              dynamic_cast<particles_t<real_t, CUDA>*>(prtcls.get()),
              params.cloudph_opts
            );
          assert(ftr.valid());
        } else 
#endif
          prtcls->step_async(params.cloudph_opts);
      }

      // performing diagnostics
      //if (this->timestep == 0 || (this->timestep % this->outfreq == 0 && this->timestep >= this->spinup))
      if (this->timestep % this->outfreq == 0) 
      { 
#if defined(STD_FUTURE_WORKS)
        if (params.async)
        {
          assert(ftr.valid());
          ftr.get();
        }
#endif
        diag();
      }
    }

    this->mem->barrier();
  }
开发者ID:igfuw,项目名称:libcloudphxx,代码行数:76,代码来源:kin_cloud_2d_lgrngn.hpp

示例6: wait_until_done

 inline void wait_until_done(std::future<T>& future) {
     if (future.valid()) {
         future.get();
     }
 }
开发者ID:dforsi,项目名称:libosmium,代码行数:5,代码来源:util.hpp

示例7: check_for_exception

 inline void check_for_exception(std::future<T>& future) {
     if (future.valid() && future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
         future.get();
     }
 }
开发者ID:dforsi,项目名称:libosmium,代码行数:5,代码来源:util.hpp

示例8: check_for_exception

 /**
  * Check task for exceptions.
  *
  * If an exception happened in the task, re-throw it in this
  * thread. This will not do anything if there was no exception.
  */
 void check_for_exception() {
     if (m_future.valid() && m_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
         m_future.get();
     }
 }
开发者ID:natsumiirimura,项目名称:libosmium,代码行数:11,代码来源:checked_task.hpp

示例9: gridding_barrier

 void gridding_barrier() {
     if (gridding_future.valid())
         gridding_future.get(); //Block until result becomes available
 }
开发者ID:ratt-ru,项目名称:bullseye,代码行数:4,代码来源:wrapper.cpp


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