unique_lock::try_lock_for Method

Attempts to obtain ownership of the associated mutex without blocking.

template<class Rep,
   class Period>
bool try_lock_for(
   const chrono::duration<Rep,
   Period>& Rel_time
);

Rel_time

A chrono::duration object that specifies the maximum amount of time that the method attempts to obtain ownership of the mutex.

true if the method successfully obtains ownership of the mutex; otherwise, false.

If the stored mutex pointer is null, the method throws a system_error that has an error code of operation_not_permitted.

If the calling thread already owns the mutex, the method throws a system_error that has an error code of resource_deadlock_would_occur.

Header: mutex

Namespace: std

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft