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 ()=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 |
| |
| const Result & | get () const |
| |
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.
- Examples
- future_example.cpp.
Definition at line 70 of file future.h.
template<typename Result >
template<typename F , typename Schedulable >
| dispenso::Future< Result >::Future |
( |
F && | f, |
|
|
Schedulable & | schedulable, |
|
|
std::launch | asyncPolicy = kNotAsync, |
|
|
std::launch | deferredPolicy = std::launch::deferred ) |
|
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.
- Parameters
-
| 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. |
Definition at line 113 of file future.h.