Attempt to acquire a lock on a std::recursive_timed_mutex object
for the current thread.
template<typename Rep,typename Period> bool try_lock_for( std::chrono::duration<Rep,Period> const& relative_time);
- Effects:
Attempts to acquire a lock on
*thisfor the calling thread within the time specified byrelative_time. Ifrelative_time.count()is zero or negative then the call will return immediately, as if it was a call totry_lock(). Otherwise, the call shall block until either the lock has been acquired or the time period specified byrelative_timehas elapsed.- Returns:
trueif a lock was obtained for the calling thread,falseotherwise.- Postconditions:
*thisis locked by the calling thread if the function returnstrue.- Throws:
Nothing.
- Note:
If the calling thread already holds the lock on
*this, the function returnstrueand the count of locks on*thisheld by the calling thread is increased by one. If the current thread does not already hold a lock on*this, the function may fail to acquire the lock (and returnfalse) even if no other thread holds a lock on*this. The thread may be blocked for longer than the specified duration. Where possible, the elapsed time is determined by a steady clock.- Throws:
Nothing
Header
#include <mutex>