public member function
<future>
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 对象。
共享状态 作为 原子操作 被访问(不会导致数据竞争)。
异常安全
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).