public member function
<future>

std::shared_future::wait_for

template <class Rep, class Period>  future_status wait_for (const chrono::duration<Rep,Period>& rel_time) const;
Wait for ready during time span
Waits for the shared state to be ready for up to the time specified by rel_time.

If the shared state is not yet ready (i.e., the provider has not yet set its value or exception), the function blocks the calling thread and waits until it is ready or until rel_time has elapsed, whichever happens first.

When the function returns because its shared state is made ready, the value or exception set on the shared state is not read, but all visible side effects are synchronized between the point the provider makes the shared state ready and the return of this function.

If the shared state contains a deferred function, the function does not block, returning immediately with a value of future_status::deferred.

引數

rel_time
The time span after which the function returns resuming execution of the calling thread.
請注意,多執行緒管理操作可能會導致超過此時間的延遲。
duration is an object that represents a specific relative time.

返回值

一個 future_status 型別的值,指示導致函式返回的原因
描述
future_status::ready共享狀態 已就緒:生產者已設定值或異常。
future_status::timeoutThe function waited for rel_time without the shared state becoming ready.
future_status::deferred共享狀態 包含 延遲函式

資料競爭

訪問了 future 物件。
共享狀態 作為 原子操作 被訪問(不會導致資料競爭)。

異常安全

Calling this member function on a shared_future object that is not valid, produces undefined behavior (although library implementations may detect this and throw future_error with a no_state error condition, offering a strong guarantee).

It may throw if an operation related to rel_time throws (note that operations on duration types provided in <chrono>, such as seconds, never throw).

另見