#include <future.h>
Inherits dispenso::detail::FutureBase< Result >.
Friends | |
template<typename T > | |
Future< std::decay_t< T > > | make_ready_future (T &&t) |
A class that implements a hybrid of the interfaces for std::experimental::future, and std::experimental::shared_future. Future
acts like a shared_future
, but includes the share
function in order to enable generic code that may use the function. See https://en.cppreference.com/w/cpp/experimental/future for more details on the API, but some differences are notable.
dispenso::Future
are created and set into executors through their constructor, or through dispenso::async
dispenso::future
can be shared around like std::experimental::shared_future
, and wait/get functions may be called concurrently from multiple threads.Future is thread-safe to call into, with the usual caveats (one thread may not be calling anything on the Future while another thread assigns to it or destructs it). It is thread-safe to assign or destruct on one copy of a Future while making calls on another copy of a Future with the same backing state.
Because Future is designed to work well with the dispenso TaskSet and ThreadPool, Future aggressively work steals in get
and wait
functions. This prevents deadlock due to thread pool resource starvation, similar to how TaskSets avoid that flavor of deadlock. It is important to note that deadlock is still possible due to traditional cyclic dependency, e.g. Future A and Future B which wait on each other. Just as with a cyclic mutex locking requirement, cyclic Future waits are considered programmer error.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Construct a Future with callable and a schedulable (e.g. a ThreadPool or TaskSet), and ensure it is scheduled according to the launch policy.
f | a functor with signature Result(void) to be invoked in order for get to return a valid value. |
schedulable | A TaskSet , ThreadPool , or similar type that has function schedule that takes a functor with signature void() and ForceQueuingTag . |
asyncPolicy | If std::launch::async , the functor will be scheduled through to the underlying thread pool work queue. |
deferredPolicy | If std::launch::deferred , wait_for and wait_until may invoke the functor from their calling thread. |
|
default |
Destruct a Future. This decrements the shared reference count (if any), and ensures the backing state is destroyed when no more references exist to the backing state.
|
inline |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
Schedule a functor to be invoked upon reaching is_ready
status, and return a future that will hold the result of the functor.
Parameters
f The functor to be executed whose result will be available in the returned Future
. This should have signature Unpecified(Future<Result>&&)
.
sched The Schedulable in which to run the functor.
asyncPolicy if std::launch::async
then the functor will attempt to be queued on the backing work queue of the Schedulable (if any).
deferredPolicy if std::launch::deferred
, wait_for
and wait_until
of the returned future will be allowed to invoke the functor, otherwise not.
- Returns
- A future containing the result of the functor.
|
inlinenoexcept |
Is this Future valid?
|
inline |
|
inline |
Wait until is_ready
is true
or until timing out.
timeoutDuration | The length of time to wait until timing out. This is relative to the current point in time. |
std::future_status::ready
if get
can return immediately, std::future_status::timeout
if the function timed out while waiting.std::launch::deferred
was specified at construction.
|
inline |
Wait until is_ready
is true
or until timing out.
timeoutTime | The absolute time to wait until timing out. |
std::future_status::ready
if get
can return immediately, std::future_status::timeout
if the function timed out while waiting.std::launch::deferred
was specified at construction.