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: P3833/P3833.md
+26-19Lines changed: 26 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,42 @@
2
2
title: "`std::multi_lock`"
3
3
---
4
4
5
-
-**Document number:**P3833R1a
5
+
-**Document number:**P3833R1
6
6
-**Date:** 2026-03-24
7
7
-**Audience:** LEWGI/SG1
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
+
## Revision History
12
+
13
+
### R1
14
+
15
+
- Rewrote postconditions throughout the wording to use prose ("is equal to", "is `true`", "is `false`") instead of `==` notation.
16
+
11
17
## Abstract
12
18
13
19
This paper proposes `std::multi_lock`, a RAII class template that combines the functionality of `std::unique_lock` and `std::scoped_lock`. Unlike `std::scoped_lock`, which provides only basic RAII semantics, `std::multi_lock` offers the full flexibility of `std::unique_lock` (deferred locking, try-lock operations, timed locking, and ownership transfer) while supporting multiple mutexes simultaneously.
14
20
15
21
## Contents
16
22
17
-
1.[Motivation](#motivation)
18
-
2.[Proposed Solution](#proposed-solution)
19
-
3.[Impact on the Standard](#impact-on-the-standard)
20
-
4.[Design Decisions](#design-decisions)
23
+
1.[Revision History](#revision-history)
24
+
2.[Motivation](#motivation)
25
+
3.[Proposed Solution](#proposed-solution)
26
+
4.[Impact on the Standard](#impact-on-the-standard)
27
+
5.[Design Decisions](#design-decisions)
21
28
-[Return value for try-lock operations](#return-value-for-try-lock-operations)
22
29
-[Timed locking with multiple mutexes](#timed-locking-with-multiple-mutexes)
This proposal is a pure library extension. It adds a new class template `std::multi_lock` to the `<mutex>` header and updates related sections of the standard to reference it. There are no changes to the core language and no breaking changes to existing code.
129
136
130
-
## 4. Design Decisions
137
+
## 5. Design Decisions
131
138
132
139
### Return value for try-lock operations
133
140
@@ -159,7 +166,7 @@ When locking multiple mutexes, `std::multi_lock` must avoid deadlock. The implem
159
166
- For `try_lock()`: Attempts to lock mutexes in order and backs off if any lock fails. It can use `std::try_lock(*get<Is>(pm)...)` for this purpose.
160
167
- For `try_lock_until()` and `try_lock_for()`: It can use an algorithm similar to `std::lock()` but with timed operations, as proposed in P3832.
**Rejected:** Both approaches require all mutexes to be of the same type. While `std::span` avoids ownership concerns and could be non-owning, it still cannot mix different mutex types (e.g., `std::mutex` and `std::timed_mutex` in the same lock). The variadic template approach maintains type safety, allows heterogeneous mutex types, and enables compile-time optimizations that would not be possible with a runtime container. Additionally, it is probably preferable to keep the interface similar to that of `unique_lock` and `scoped_lock` to complete the family of mutex wrapper classes with a consistent design.
258
265
259
-
## 7. Implementation Experience
266
+
## 8. Implementation Experience
260
267
261
268
A complete implementation is available at [github.com/bemanproject/timed_lock_alg](https://github.com/bemanproject/timed_lock_alg). The implementation has been tested with multiple mutex types and demonstrates that the design is implementable and practical.
0 commit comments