|
stlab 2.4.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
|
Blocking wait helpers for futures (await, await_for, …). More...
#include <stlab/config.hpp>#include <chrono>#include <condition_variable>#include <exception>#include <mutex>#include <utility>#include <stlab/concurrency/future.hpp>#include <stlab/concurrency/immediate_executor.hpp>#include <stlab/concurrency/ready_future.hpp>#include <stlab/memory.hpp>#include <stlab/concurrency/default_executor.hpp>Go to the source code of this file.
Functions | |
| template<class F> | |
| auto | stlab::invoke_waiting (F &&f) |
| Assumes f will block waiting; on the portable task system, wakes the pool or adds a worker (up to the limit) before calling f. Terminates without invoking f when the core uses cooperative threadless execution. | |
| template<class T> | |
| auto | stlab::await (future< T > &&x) -> T |
| Synchronously wait for the result x. If x resolves as an exception, the exception is rethrown. When using the portable task system, an additional thread is added to the pool if no threads are available and the maximum number of threads has not been reached. In cooperative threadless execution, terminates if x is not already ready. | |
| template<class T> | |
| auto | stlab::await (const future< T > &x) -> T |
| Equivalent to await(copy(x)). | |
| template<class T> | |
| auto | stlab::await_for (future< T > &&x, const std::chrono::nanoseconds &timeout) -> future< T > |
| Waits at most timeout, returning a future that retains any pending result. In cooperative threadless execution, ignores timeout and returns immediately without waiting. Repeated polling must yield to the host event loop to allow the result to become ready. | |
| template<class T> | |
| auto | stlab::await_for (const future< T > &x, const std::chrono::nanoseconds &timeout) -> future< T > |
| Equivalent to await_for(copy(x), timeout). | |
Blocking wait helpers for futures (await, await_for, …).
Prefer continuations on futures; blocking waits can increase contention, grow the thread pool, or deadlock. For discussion of these issues, see Sean Parent’s talk “C++ Seasoning”.
On the portable task system, invoke_waiting may wake the pool or add a worker before a blocking-style wait runs (see implementation).