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


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

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


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

示例1: IsReady

  static bool IsReady(std::future<void>& future)
  {
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
    return future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
#else
    return future.wait_for(std::chrono::seconds(0));
#endif
  }
开发者ID:arrrrrrr,项目名称:ebftpd,代码行数:8,代码来源:futureminder.hpp

示例2: check_for_computed_move

void GoApp::check_for_computed_move()
{
	//return;

	if (game_status != COMPUTER_THINKING) {
		return;
	}

	auto status = computed_move.wait_for(std::chrono::seconds(0));
	if (status == std::future_status::ready) {
		try {
			auto move = computed_move.get();
			state.do_move(move);

			// Are there any more moves possible?
			if (state.get_moves().empty()) {
				game_status = GAME_OVER;
			}
			else {
				next_player();
			}

		} catch (std::exception& error) {
			game_status = GAME_ERROR;
			error_string = error.what();
		}
	}
}
开发者ID:CatalinTiseanu,项目名称:monte-carlo-tree-search,代码行数:28,代码来源:go.cpp

示例3: 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

示例4: interruptible_wait

void interruptible_wait(std::future<T>& uf)
{
	while (!this_thread_interrupt_flag.is_set())
	{
		if (uf.wait_for(lk, std::future_status::ready == std::chrono::milliseconds(1)))
			break;
	}
}
开发者ID:DevStarSJ,项目名称:Study,代码行数:8,代码来源:ch.09.02.05.handling_interrupt.cpp

示例5: test

void test(std::future<void> fut)
{    
    switch (fut.wait_for(std::chrono::milliseconds(500)))
    {
        case std::future_status::ready: std::cout << "ready\n"; break;
        case std::future_status::deferred: std::cout << "deferred\n"; break;
        case std::future_status::timeout: std::cout << "timeout\n"; break;
    };
}
开发者ID:CCJY,项目名称:coliru,代码行数:9,代码来源:main.cpp

示例6: threadFunc

//----------------------------------------------------------------------//
void SoftServo::threadFunc(std::future<bool> shutdown,
			   SoftServo *const servo) // change this in the future to use a thread safe shared pipe reader/writer
{
  while (shutdown.wait_for(std::chrono::nanoseconds(0)) != 
	 std::future_status::ready)
    {
      servo->updateMove();
    }
}
开发者ID:Gregory119,项目名称:Robotics,代码行数:10,代码来源:ctrl_softservo.cpp

示例7: checkIfFinished

static bool checkIfFinished(std::future<void>& match) {
    auto status = match.wait_for(std::chrono::seconds(0));
    if(status == std::future_status::timeout) {
        return false;
    }
    else if(status == std::future_status::ready) {
        return true;
    }
    else {
        return false;
    }
}
开发者ID:kamszyc,项目名称:checkers-server,代码行数:12,代码来源:MatchHandler.cpp

示例8: threadFunc

//----------------------------------------------------------------------//
void JoyStick::threadFunc(std::future<bool> shutdown,
			  const JoyStick *const js)
{
  while (shutdown.wait_for(std::chrono::nanoseconds(0)) != 
	 std::future_status::ready)
    {
      if (!js->readEvent())
	{
	  js->d_owner->handleReadError();
	}
    }
}
开发者ID:Gregory119,项目名称:Robotics,代码行数:13,代码来源:djs_joystick.cpp

示例9: WaitForFuture

void AI::WaitForFuture(const std::future<void>& fut, bool bPondering)
{
	std::uint64_t timePerMove = GetTimePerMove();
	if(bPondering)
	{
		timePerMove /= 2;
	}

	// Wait until the thread finishes or it gets timed out
	if(fut.wait_for(std::chrono::nanoseconds(timePerMove)) == std::future_status::timeout)
	{
		// If the thread did not finish execution, signal the thread to exit, and wait till the thread exits.
	
		m_bStopMinimax = true;
		fut.wait();
		m_bStopMinimax = false;
	}
}
开发者ID:BryceMehring,项目名称:Chess,代码行数:18,代码来源:AI.cpp

示例10: 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

示例11: is_ready

 bool is_ready(std::future<R> const& f) {
    return f.wait_for(std::chrono::microseconds(0)) == std::future_status::ready;
 }
开发者ID:KjellKod,项目名称:concurrent,代码行数:3,代码来源:concurrent.hpp

示例12: waitForFuture

bool waitForFuture(std::future<T>& f, std::chrono::seconds timeout = std::chrono::seconds{5})
{
  return f.wait_for(timeout) == std::future_status::ready;
}
开发者ID:el-bart,项目名称:but,代码行数:4,代码来源:waitForFuture.ut.hpp

示例13: is_ready

bool is_ready(std::future<T>& f)
{
    return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
}
开发者ID:Nocte-,项目名称:hexahedra,代码行数:4,代码来源:threadpool.hpp

示例14: 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

示例15: 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


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