void apply(future<void> f) const { if (f.ready()) return; task_context* ctx = current_task_context::get(); if (!ctx) { f.wait(); return; } auto&& resume_task = [=]() { ctx->resume(); }; auto s = f.get_state(detail::use_private_interface); s->continue_with([&]() { s->await_queue()->push_front([=]() { resume_task(); }); }); ctx->yield(); }
void future_answer() { //int x=the_answer_to_life_the_universe_and_everything.get_future().get(); //如果上面注释的这句话就会出错! int x=fut.get(); cout<<x<<endl; }
type operator()(future<T> const& x) const { if (auto&& state = x.get_state(use_private_interface)) return state->template then<future<void>>(std::bind([](){})); else return make_ready_future(); }
future<naming::id_type> migrate_component_postproc( future<boost::shared_ptr<Component> > f, naming::id_type const& to_migrate, naming::id_type const& target_locality) { using components::stubs::runtime_support; boost::shared_ptr<Component> ptr = f.get(); boost::uint32_t pin_count = ptr->pin_count(); if (pin_count == ~0x0u) { HPX_THROW_EXCEPTION(invalid_status, "hpx::components::server::migrate_component", "attempting to migrate an instance of a component which was " "already migrated"); return make_ready_future(naming::invalid_id); } if (pin_count > 1) { HPX_THROW_EXCEPTION(invalid_status, "hpx::components::server::migrate_component", "attempting to migrate an instance of a component which is " "currently pinned"); return make_ready_future(naming::invalid_id); } return runtime_support::migrate_component_async<Component>( target_locality, ptr, to_migrate) .then(util::bind( &detail::migrate_component_cleanup<Component>, util::placeholders::_1, ptr, to_migrate)); }
static void crypto_one_test(const string &name, future<ContextReply> context, const vector<uint8_t> expected) { auto result = context.get().data; if (!equal(expected.begin(), expected.end(), result.begin())) { throw runtime_error(name + ": Ошибка тестирования"); } }
naming::id_type migrate_to_storage_here_cleanup( future<naming::id_type> f, boost::shared_ptr<Component> ptr, naming::id_type const& to_migrate) { ptr->mark_as_migrated(); return f.get(); }
~impl() { try { _rotation_task.cancel_and_wait("file_appender is destructing"); } catch( ... ) { } }
/* Asynchronously provide data with promise */ int factorial(future<int>& f) { // do something else int N = f.get(); // If promise is distroyed, exception: std::future_errc::broken_promise cout << "Got from parent: " << N << endl; int res = 1; for (int i=N; i>1; i--) res *= i; return res; }
int promiseDependingFunction(future<int>& fu) { //... do some work setting up the environment... this_thread::sleep_for(chrono::milliseconds(100)); //ready to wait for promise to be fufilled int value = fu.get(); //use value value *= 16; return value; }
template<typename T> inline exception_ptr get_exception_ptr(future<T> &f) { #if 1 // Thanks to Vicente for adding this to Boost.Thread return f.get_exception_ptr(); #else // This seems excessive but I don't see any other legal way to extract the exception ... bool success=false; try { f.get(); success=true; } catch(...) { exception_ptr e(afio::make_exception_ptr(afio::current_exception())); assert(e); return e; } return exception_ptr(); #endif }
void operator()(future<double> r) const { global_scratch += r.get(); }
HPX_FORCEINLINE result_type operator()(future<Derived> f) const { return f.get().share(); }
void producer( future & f ) { f.set_exception (boost::copy_exception (err () << answer(42))); }
future(const future<T> &other) : m_event(other.get_event()) { }
int future_int_f1(future<void> f1) { HPX_TEST(f1.is_ready()); ++future_int_f1_count; return 1; }
bool valid() const { return listener.valid(); }
static future<Result> call(future<Result> f) { HPX_ASSERT(f.has_exception()); // Intel complains if this is not explicitly moved return std::move(f); }
shared_future(future<T>&& future) : state(new shared_state_multiplexer<T>(std::move(future)) ) , listener(state->add_listener()) { assert(listener.valid()); }
void worker1(future<int> fut) { printf("this is thread1\n"); flag = 1; fut.get(); printf("thread1 exit\n"); }
int operator()(future<int> msg) { int id = Futures_Id(); std::cout << "Waiting for future on " << id << endl; return msg.get(); };
void future_void_f1(future<void> f1) { HPX_TEST(f1.is_ready()); ++future_void_f1_count; }
int future_int_f2(future<int> f1, future<int> f2) { HPX_TEST(f1.is_ready()); HPX_TEST(f2.is_ready()); ++future_int_f2_count; return f1.get() + f2.get(); }
static bool erase_vorbis_stream(const future<vector<float>>& fut) { return !fut.valid(); }
bool ready() const { return listener.ready(); }
void insert(const future<T> &future) { insert(future.get_event()); }
void wait(WaitStrategy&& strategy) { listener.wait(strategy); }
// This function will be called for every file opened static void open_file_filter(detail::OpType, future<> &op) noexcept { std::cout << "File handle " << op->native_handle() << " opened!" << std::endl; }
void wait() { listener.wait(); }
shared_future(const shared_future& rhs) : state(rhs.state) , listener(state ? state->add_listener() : future<bool>()) { assert(listener.valid()); }
void future_void_f2(future<void> f1, future<void> f2) { HPX_TEST(f1.is_ready()); HPX_TEST(f2.is_ready()); ++future_void_f2_count; }