...
This compliant solution uses Standard Template Library facilities to ensure that deadlock does not occur due to circular wait conditions. The std::lock()
function takes a variable number of lockable objects and attempts to lock them such that deadlock does not occur [ISO/IEC 14882-2014]. In typical implementations, this is done by using a combination of lock()
, try_lock()
, and unlock()
to attempt to lock the object and backing off if the lock is not acquired, which may have worse performance than a solution that locks in predefined order explicitly.
...
CERT Oracle Secure Coding Standard for Java | LCK07-J. Avoid deadlock by requesting and releasing locks in the same order |
MITRE CWE | CWE-764, Multiple Locks of a Critical Resource |
Bibliography
[ISO/IEC 14882-2014] | Subclause 30.4, "Mutual Exclusion" |
...