You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: papers/P3832.md
+20-14Lines changed: 20 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,14 +2,25 @@
2
2
title: "Timed lock algorithms for multiple lockables"
3
3
---
4
4
5
-
-**Document number:**P3832R0
5
+
-**Document number:**P3832R1
6
6
-**Date:**@DATE@
7
7
-**Audience:** Library Evolution Working Group
8
8
-**Project:** ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
9
9
-**Reply-to:** Ted Lyngmo <ted@lyncon.se>
10
10
11
11
## Revision History
12
12
13
+
### R1
14
+
15
+
- Added link to reference implementation.
16
+
17
+
Modifications after `2025-11_Kona:SG1-P3832R0` meeting:
18
+
19
+
- Added a note that an implementation should ensure that `try_lock_until()` does not consistently return ≥ 0 in the absence of contending mutex acquisitions.
20
+
- Clarified that no call to `try_lock_for()` or `try_lock_until()` is made while holding a lock on any argument.
21
+
- Added `Throws` clause to `try_lock_until`.
22
+
- Changed "the index of the last lockable for which locking failed" to "the index of the lockable for which `try_lock_until()` or `try_lock_for()` failed due to `abs_time` being reached" in Effects and Returns.
23
+
13
24
## Abstract
14
25
15
26
C++11 introduced `std::lock` and `std::try_lock` (and C++17 introduced `std::scoped_lock`) to simplify deadlock-free acquisition of multiple lockables. These algorithms support *BasicLockable* and *Lockable* objects, but there is currently no facility for timed acquisition of multiple *TimedLockable* objects.
@@ -59,7 +70,7 @@ These extend the `std::lock` family of functions to timed lockables, enabling co
59
70
60
71
## 5. Proposed Wording
61
72
62
-
The following changes are relative to N5008.
73
+
The following changes are relative to N5014.
63
74
64
75
In 32.6.6, Generic locking algorithms [thread.lock.algorithm], after point 5:
65
76
@@ -70,14 +81,11 @@ int try_lock_until(const chrono::time_point<Clock, Duration>& abs_time, Ls&... l
70
81
71
82
**6** *Preconditions*: Each template parameter type in `Ls` meets the *Cpp17TimedLockable* requirements.
72
83
73
-
**7** *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, but is otherwise unspecified.
74
-
75
-
- If all locks are acquired before `abs_time` has passed, returns `-1`.
76
-
- If the time point `abs_time` is reached before all locks are acquired, releases any locks it holds and returns the index of the last lockable for which locking failed.
84
+
**7** *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.
77
85
78
-
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.
86
+
**8** *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.
79
87
80
-
**8** *Returns*: `-1` if all locks were obtained, otherwise the index of the last lockable for which locking failed.
88
+
**9** *Throws*: Any exception thrown by the lockable `try_lock_until()`, `try_lock_for()`, or `try_lock()` functions.
**9** *Preconditions*: Each template parameter type in `Ls` meets the *Cpp17TimedLockable* requirements.
88
96
89
-
**10** *Effects*: Equivalent to:
Existing implementations of `std::lock` already use a deadlock-avoidance algorithm. Using the gcc implementation as an example, instead of locking one with `m.lock()` and using `std::try_lock()` on the rest, the algorithm could start locking one with `m.try_lock_until(tp)`. [Example at Compiler Explorer](https://godbolt.org/z/Ya7Pbq85P)
111
115
116
+
A reference implementation is available at [github.com/bemanproject/timed_lock_alg](https://github.com/bemanproject/timed_lock_alg).
117
+
112
118
## 8. Acknowledgments
113
119
114
120
The std-proposals mailing list:
@@ -123,4 +129,4 @@ Reference implementation:
123
129
124
130
## 9. References
125
131
126
-
-N5008: Working Draft, Programming Languages — C++ (C++26).
132
+
-N5014: Working Draft, Programming Languages — C++ (C++26).
Copy file name to clipboardExpand all lines: papers/P3833.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: "`std::multi_lock`"
3
3
---
4
4
5
-
-**Document number:**P3833R2a
5
+
-**Document number:**P3833R2
6
6
-**Date:**@DATE@
7
7
-**Audience:** LEWGI/SG1
8
8
-**Project:** ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
@@ -13,6 +13,7 @@ title: "`std::multi_lock`"
13
13
### R2
14
14
15
15
- Removed _Attempts to lock all mutexes using a deadlock-avoidance algorithm until `abs_time`_ from `try_lock_until`_Effects_ after unanimous vote in Croydon.
16
+
- Clarified that no call to `try_lock_for()` or `try_lock_until()` is made while holding a lock on any element of `pm` in `try_lock_until`_Effects_, to harmonize with the updated wording in P3832.
16
17
17
18
### R1
18
19
@@ -506,7 +507,7 @@ template<class Clock, class Duration>
506
507
507
508
**14***Preconditions*: All types in `MutexTypes` meet the *Cpp17TimedLockable* requirements (32.2.5.4).
508
509
509
-
**15***Effects*: If `sizeof...(MutexTypes)` equals 0, returns -1. Otherwise, if `sizeof...(MutexTypes)` equals 1, calls `get<0>(pm)->try_lock_until(abs_time)` and returns -1 if successful, 0 otherwise. Otherwise, uses an algorithm similar to `lock()` but with timed operations respecting `abs_time`.
510
+
**15***Effects*: If `sizeof...(MutexTypes)` equals 0, returns -1. Otherwise, if `sizeof...(MutexTypes)` equals 1, calls `get<0>(pm)->try_lock_until(abs_time)` and returns -1 if successful, 0 otherwise. Otherwise, uses an algorithm similar to `lock()` but with timed operations respecting `abs_time`. No call to `try_lock_for()` or `try_lock_until()` is made while holding a lock on any element of `pm`.
510
511
511
512
**16***Postconditions*: `owns` is `true` if the return value equals -1, otherwise `false`.
0 commit comments