Attempts to acquire a lock on the mutex associated with *this
within the time specified.
template<typename Rep, typename Period> bool try_lock_for(std::chrono::duration<Rep,Period> const& relative_time);
- Preconditions:
The
Mutextype used to instantiatestd::unique_lockmust meet theTimedLockablerequirements.this->mutex()!=NULL,this->owns_lock()==false.- Effects:
Calls
this->mutex()->try_lock_for(relative_time).- Returns:
trueif the call tothis->mutex()->try_lock_for()returnedtrue,falseotherwise.- Throws:
Any exceptions thrown by
this->mutex()->try_lock_for().std::system_errorwith an error code ofstd::errc::operation_not_permittedifthis->mutex()==NULL.std::system_errorwith an error code ofstd::errc::resource_deadlock_would_occurifthis->owns_lock()==trueon entry.- Postcondition:
If the function returns
true,this->owns_lock()==true, otherwisethis->owns_lock()==false.
Header
#include <mutex>