Documentation Home >> Headers >> <mutex> Header >> std::timed_mutex >> std::timed_mutex::try_lock Member Function

Attempt to acquire a lock on a std::timed_mutex object for the current thread.

bool try_lock();

Effects:

Attempts to acquire a lock on *this for the calling thread without blocking.

Returns:

true if a lock was obtained for the calling thread, false otherwise.

Postconditions:

*this is locked by the calling thread if the function returns true.

Throws:

Nothing.

Note:

If the calling thread already holds the lock on *this, the function returns false. The function may fail to acquire the lock (and return false) even if no other thread holds a lock on *this.

Header

#include <mutex>

See Also