Showing content from https://cplusplus.com/reference/mutex/timed_mutex/try_lock/ below:
public member function
<mutex>
std::timed_mutex::try_lock
Lock timed mutex if not locked
Attempts to lock the timed_mutex, without blocking (it behaves exactly as in mutex):
- If the timed_mutex isn't currently locked by any thread, the calling thread locks it (from this point, and until its member unlock is called, the thread owns the timed_mutex).
- If the timed_mutex is currently locked by another thread, the function fails and returns
false
, without blocking (the calling thread continues its execution).
- If the timed_mutex is currently locked by the same thread calling this function, it produces a deadlock (with undefined behavior). See recursive_timed_mutex for a timed mutex type that allows multiple locks from the same thread.
This function may fail spuriously when no other thread has a lock on the timed_mutex, but repeated calls in these circumstances shall succeed at some point.
All lock and unlock operations on the timed_mutex follow a single total order, with all visible effects synchronized between the lock operations and previous unlock operations on the same object.
Parameters none
Return valuetrue
if the function succeeds in locking the timed_mutex for the thread.
false
otherwise.
Data races The timed_mutex object is accessed/modified as an atomic operation (causes no data races).
Exception safety If the timed_mutex isn't currently locked by the calling thread, this function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior.
See also
-
timed_mutex::try_lock_for
-
Try to lock for time span (public member function)
-
timed_mutex::try_lock_until
-
Try to lock until time point (public member function)
-
timed_mutex::lock
-
Lock timed mutex (public member function)
-
timed_mutex::unlock
-
Unlock timed mutex (public member function)
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4