std::packaged_task<int(int,int)>tsk(countdown);// set up packaged_taskstd::future<int> ret = tsk.get_future();
std::packaged_task<int(int,int)>tsk (countdown); // set up packaged_task std::future<int>ret = tsk.get_future(); 1. 2.
类模板std::packaged_task包装任何可调用(Callable)目标(函数、lambda 表达式、bind 表达式或其他函数对象),使得能异步调用它。其返回值或所抛异常被存储于能通过std::future对象访问的共享状态中。 正如std::function,std::packaged_task是多态、具分配器的容器:可在堆上或以提供的分配器分配其所存储的可调用目标。
Task_Wrapper 必须能移动封装 std::packaged_task<R()> 对象(#1)。为了保持一致性,Task_Wrapper 也实现了移动构造(#2)和移动赋值(#3),同时实现了 operator()(#4)。ABC 的继承结构(#5)用于支持泛型化地封装和调用 std::packaged_task<> 对象。std::packaged_task<> 封装在派生类 Task<> 中(#6),由指...
(Args...)>::type,void>::value>::type>autoenqueue(F&&Func_F,Args&&...Args_F)->std::future<typenamestd::result_of<F(Args...)>::type>{usingreturn_type=typenamestd::result_of<F(Args...)>::type;autopkgTask=std::make_shared<std::packaged_task<return_type()>>(std::bind(std::...
cpp6 std::future future对象通过以下方式获得 async promise::get_future packaged_task::get_future
void swap( packaged_task<Function(Args...)> &lhs, packaged_task<Function(Args...)> &rhs ) noexcept; (since C++11) Specializes the std::swap algorithm for std::packaged_task. Exchanges the state of lhs with that of rhs. Effectively calls lhs.swap(rhs). Parameters lhs, rhs - pack...
packaged_task::operator= packaged_task::valid packaged_task::swap Getting the result packaged_task::get_future Execution packaged_task::operator() packaged_task::make_ready_at_thread_exit packaged_task::reset Non-member functions swap(std::packaged_task) Helper classes uses_allocator<std::packaged...
std::packaged_task<R(Args...)>::operator()C++ 并发支持库 std::packaged_task void operator()( ArgTypes... args ); (C++11 起) 如同以 INVOKE<R>(f, args...) 调用存储的任务 f。任务返回值或任何抛出的异常被存储于共享状态。令共享状态就绪,并解除阻塞任何等待此操作的线程。
The RStein.AsyncCpp library is a set of types that should be familiar for anyone who knows the Task Parallel Library (TPL) for .NET (C#). In addition, this library contains simple DataFlow, threadless actors (agents), functional combinators for the Task class, useful async primitives (Async...