Attempt to acquire a lock on a std::mutex object for the current
thread.
bool try_lock();
- Effects:
Attempts to acquire a lock on
*thisfor the calling thread without blocking.- 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 returnsfalse. The function may fail to acquire the lock (and returnfalse) even if no other thread holds a lock on*this.
Header
#include <mutex>