|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Locking | ||||
timed_mutex::try_lock_until | ||||
| Native handle | ||||
template<class Clock,class Duration> bool try_lock_until(conststd::chrono::time_point<Clock, Duration>& timeout_time); | (since C++11) | |
Tries to lock the mutex. Blocks until specifiedtimeout_time has been reached (timeout) or the lock is acquired (owns the mutex), whichever comes first. On successful lock acquisition returnstrue, otherwise returnsfalse.
Iftimeout_time has already passed, this function behaves liketry_lock().
Clock must meet theClock requirements. The program is ill-formed ifstd::chrono::is_clock_v<Clock> isfalse.(since C++20)
The standard recommends that the clock tied totimeout_time be used, in which case adjustments of the clock may be taken into account. Thus, the duration of the block might be more or less thantimeout_time- Clock::now() at the time of the call, depending on the direction of the adjustment and whether it is honored by the implementation. The function also may block until aftertimeout_time has been reached due to process scheduling or resource contention delays.
As withtry_lock(), this function is allowed to fail spuriously and returnfalse even if the mutex was not locked by any other thread at some point beforetimeout_time.
Priorunlock() operation on the same mutexsynchronizes-with (as defined instd::memory_order) this operation if it returnstrue.
Iftry_lock_until is called by a thread that already owns the mutex, the behavior is undefined.
Contents |
| timeout_time | - | maximum time point to block until |
true if the lock was acquired successfully, otherwisefalse.
Any exception thrown bytimeout_time (clocks, time points, and durations provided by the standard library never throw).
| This section is incomplete Reason: no example |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2093 | C++11 | try_lock_until threw nothing | throws timeout-related exceptions |
| locks the mutex, blocks if the mutex is not available (public member function)[edit] | |
| tries to lock the mutex, returns if the mutex is not available (public member function)[edit] | |
| tries to lock the mutex, returns if the mutex has been unavailable for the specified timeout duration (public member function)[edit] | |
| unlocks the mutex (public member function)[edit] | |
C documentation formtx_timedlock | |