try_lock
?Section: 32.6.6 [thread.lock.algorithm] Status: C++20 Submitter: Jonathan Wakely Opened: 2017-11-07 Last modified: 2021-02-25
Priority: 0
View all other issues in [thread.lock.algorithm].
View all issues with C++20 status.
Discussion:
32.6.6 [thread.lock.algorithm] says:
"If a call to
try_lock()
fails,unlock()
shall be called for all prior arguments and there shall be no further calls totry_lock()
."
We try to use "shall" for requirements on the user (e.g. as in the previous paragraph) which is absolutely not what is meant here.
[2017-11 Albuquerque Wednesday night issues processing]
Moved to Ready
[2018-3-17 Adopted in Jacksonville]
Proposed resolution:
This wording is relative to N4700.
Change 32.6.6 [thread.lock.algorithm] as indicated:
template <class L1, class L2, class... L3> int try_lock(L1&, L2&, L3&...);-1- Requires: […]
-2- Effects: Callstry_lock()
for each argument in order beginning with the first until all arguments have been processed or a call totry_lock()
fails, either by returningfalse
or by throwing an exception. If a call totry_lock()
fails,unlock()
shall beis called for all prior argumentsand there shall bewith no further calls totry_lock()
. […]template <class L1, class L2, class... L3> void lock(L1&, L2&, L3&...);-4- Requires: […]
-5- Effects: All arguments are locked via a sequence of calls tolock()
,try_lock()
, orunlock()
on each argument. The sequence of callsshalldoes 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 tolock()
ortry_lock()
throws an exception,unlock()
shall beis called for any argument that had been locked by a call tolock()
ortry_lock()
.