Skip to content

Commit 98096a9

Browse files
committed
RWLock: Add deadlock example
Suggested in rust-lang#82596 but it was a bit too late. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 6e2801c commit 98096a9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

library/std/src/sync/rwlock.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ use crate::sys_common::rwlock as sys;
2525
/// system's implementation, and this type does not guarantee that any
2626
/// particular policy will be used. In particular, a writer which is waiting to
2727
/// acquire the lock in `write` might or might not block concurrent calls to
28-
/// `read`.
28+
/// `read`, e.g.:
29+
///
30+
/// <details><summary>Potential deadlock example</summary>
31+
///
32+
/// ```text
33+
/// // Thread 1 | // Thread 2
34+
/// let _rg = lock.read(); |
35+
/// | // will block
36+
/// | let _wg = lock.write();
37+
/// // may deadlock |
38+
/// let _rg = lock.read(); |
39+
/// ```
40+
/// </details>
2941
///
3042
/// The type parameter `T` represents the data that this lock protects. It is
3143
/// required that `T` satisfies [`Send`] to be shared across threads and

0 commit comments

Comments
 (0)