Inherits dispenso::detail::FutureBase< Result >.
|
| Future () noexcept |
|
| Future (Future &&f) noexcept |
|
| Future (Base &&f) noexcept |
|
| Future (const Future &f) noexcept |
|
| Future (const Base &f) noexcept |
|
template<typename F , typename Schedulable > |
| Future (F &&f, Schedulable &schedulable, std::launch asyncPolicy=kNotAsync, std::launch deferredPolicy=std::launch::deferred) |
|
Future & | operator= (Future &&f) noexcept |
|
Future & | operator= (const Future &f) |
|
| ~Future ()=default |
|
bool | valid () const noexcept |
|
bool | is_ready () const |
|
void | wait () const |
|
template<class Rep , class Period > |
std::future_status | wait_for (const std::chrono::duration< Rep, Period > &timeoutDuration) const |
|
template<class Clock , class Duration > |
std::future_status | wait_until (const std::chrono::time_point< Clock, Duration > &timeoutTime) const |
|
Future | share () |
|
const Result & | get () const |
|
template<typename F , typename Schedulable > |
Future< detail::ResultOf< F, Future< Result > && > > | then (F &&f, Schedulable &sched, std::launch asyncPolicy=kNotAsync, std::launch deferredPolicy=std::launch::deferred) |
|
template<typename F > |
Future< detail::ResultOf< F, Future< Result > && > > | then (F &&f) |
|
template<typename Result>
class dispenso::Future< Result >
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.
Definition at line 69 of file future.h.
template<typename Result >
template<typename F , typename Schedulable >
Future< detail::ResultOf< F, Future< Result > && > > dispenso::Future< Result >::then |
( |
F && | f, |
|
|
Schedulable & | sched, |
|
|
std::launch | asyncPolicy = kNotAsync, |
|
|
std::launch | deferredPolicy = std::launch::deferred ) |
|
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.
Definition at line 239 of file future.h.