33 Thread support library [thread]

33.4 Mutual exclusion [thread.mutex]

33.4.5 Generic locking algorithms [thread.lock.algorithm]

template <class L1, class L2, class... L3> int try_lock(L1&, L2&, L3&...);
Requires: Each template parameter type shall meet the Lockable requirements.
[ Note
:
The unique_­lock class template meets these requirements when suitably instantiated.
— end note
 ]
Effects: Calls try_­lock() for each argument in order beginning with the first until all arguments have been processed or a call to try_­lock() fails, either by returning false or by throwing an exception.
If a call to try_­lock() fails, unlock() shall be called for all prior arguments and there shall be no further calls to try_­lock().
Returns: -1 if all calls to try_­lock() returned true, otherwise a zero-based index value that indicates the argument for which try_­lock() returned false.
template <class L1, class L2, class... L3> void lock(L1&, L2&, L3&...);
Requires: Each template parameter type shall meet the Lockable requirements,
[ Note
:
The unique_­lock class template meets these requirements when suitably instantiated.
— end note
 ]
Effects: All arguments are locked via a sequence of calls to lock(), try_­lock(), or unlock() on each argument.
The sequence of calls shall not result in deadlock, but is otherwise unspecified.
[ Note
:
A deadlock avoidance algorithm such as try-and-back-off must be used, but the specific algorithm is not specified to avoid over-constraining implementations.
— end note
 ]
If a call to lock() or try_­lock() throws an exception, unlock() shall be called for any argument that had been locked by a call to lock() or try_­lock().