Skip to content

Commit 92e2a1e

Browse files
committed
Update P3832R2a after Brno:SG1
Signed-off-by: Ted Lyngmo <ted@lyncon.se>
1 parent 7f8c37b commit 92e2a1e

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

papers/P3832.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ title: "Timed lock algorithms for multiple lockables"
1010

1111
## Revision History
1212

13+
### R2
14+
15+
Modifications after `P3832R1:SG1:Brno_2026` meeting:
16+
17+
- Rewrote Effects to explicitly describe the algorithm: `try_lock_until` on one lockable, then `try_lock()` on the rest, with unlock-and-retry semantics.
18+
- Added "This function does not rely on timeouts for deadlock avoidance."
19+
- Changed "An implementation should ensure..." to normative "This function does not consistently return ≥ 0 in the absence of contending mutex acquisitions."
20+
- Removed `try_lock_for()` from Effects; the algorithm is now specified in terms of `try_lock_until()` and `try_lock()` only.
21+
- Rewrote Returns to: "the index of the lockable that the implementation was attempting to acquire when the time point `abs_time` was reached."
22+
- Dropped "in `Ls`" from Preconditions to match standard style.
23+
1324
### R1
1425

1526
- Added link to reference implementation.
@@ -79,20 +90,20 @@ template <class Clock, class Duration, class... Ls>
7990
int try_lock_until(const chrono::time_point<Clock, Duration>& abs_time, Ls&... ls);
8091
```
8192

82-
**6** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Preconditions*: Each template parameter type in `Ls` meets the *Cpp17TimedLockable* requirements.
93+
**6** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Preconditions*: Each template parameter type meets the *Cpp17TimedLockable* requirements.
8394

84-
**7** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Effects*: Attempts to obtain ownership of all arguments via repeated calls to `try_lock_until()`, `try_lock_for()`, `try_lock()` or `unlock()` on each argument. The sequence of calls does not result in deadlock. No call to `try_lock_for()` or `try_lock_until()` is made while holding a lock on any argument, but the sequence is otherwise unspecified. If all locks are acquired before `abs_time` has passed, returns `-1`. If the time point `abs_time` is reached before all locks are acquired, releases any locks it holds and returns the index of the lockable for which `try_lock_until()` or `try_lock_for()` failed due to `abs_time` being reached. If a call to `try_lock_until()`, `try_lock_for()` or `try_lock()` throws an exception, `unlock()` is called on any object locked by this algorithm prior to the exception, and the exception is rethrown.<br>An implementation should ensure that `try_lock_until()` does not consistently return ≥ 0 in the absence of contending mutex acquisitions.
95+
**7** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Effects*: Calls `try_lock_until(l, abs_time)` on an unspecified lockable `l` from `ls`. If this returns `true`, then `try_lock()` is called on the other lockables of `ls` in an unspecified order until all have been locked or one fails. If all calls to `try_lock()` return `true`, the overall operation succeeds. Otherwise, `unlock()` is called for all lockables for which `try_lock()` or `try_lock_until()` returned `true`, and the above steps are repeated until the time point `abs_time` has been reached. The sequence in which locks are obtained does not result in deadlock. This function does not rely on timeouts for deadlock avoidance. This function does not consistently return ≥ 0 in the absence of contending mutex acquisitions. If a call to `try_lock_until()` or `try_lock()` throws an exception, `unlock()` is called for any lockable that was locked by this algorithm prior to the exception, and the exception is rethrown.<br>[*Note 1*: The lockable `l` chosen may be the same or different for multiple executions of the loop. — *end note*]
8596

86-
**8** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Returns*: `-1` if all locks were obtained, otherwise the index of the lockable for which `try_lock_until()` or `try_lock_for()` failed due to `abs_time` being reached.
97+
**8** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Returns*: `-1` if all locks were obtained, otherwise the index of the lockable that the implementation was attempting to acquire when the time point `abs_time` was reached.
8798

88-
**9** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Throws*: Any exception thrown by the lockable `try_lock_until()`, `try_lock_for()`, or `try_lock()` functions.
99+
**9** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Throws*: Any exception thrown by the lockable `try_lock_until()` or `try_lock()` functions.
89100

90101
```cpp
91102
template <class Rep, class Period, class... Ls>
92103
int try_lock_for(const chrono::duration<Rep, Period>& rel_time, Ls&... ls);
93104
```
94105
95-
**9** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Preconditions*: Each template parameter type in `Ls` meets the *Cpp17TimedLockable* requirements.
106+
**9** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Preconditions*: Each template parameter type meets the *Cpp17TimedLockable* requirements.
96107
97108
**10** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Effects*: Equivalent to:<br>`return try_lock_until(chrono::steady_clock::now() + rel_time, ls...);`
98109

0 commit comments

Comments
 (0)