stlab 2.3.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
Loading...
Searching...
No Matches
await.hpp File Reference

Blocking wait helpers for futures (await, await_for, deprecated blocking_get, …). 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>

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.
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.
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 >
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).
template<class T>
auto stlab::blocking_get (future< T > x) -> T
template<class T>
auto stlab::blocking_get_for (future< T > x, const std::chrono::nanoseconds &timeout) -> future< T >
template<class T>
auto stlab::blocking_get (future< T > x, const std::chrono::nanoseconds &timeout) -> decltype(x.get_try())

Detailed Description

Blocking wait helpers for futures (await, await_for, deprecated blocking_get, …).

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).