Skip to content

Commit 17ea490

Browse files
committed
Auto merge of rust-lang#82624 - ojeda:rwlock-example-deadlock, r=JohnTitor
RWLock: Add deadlock example Suggested in rust-lang#82596 but it was a bit too late. `@matklad` `@azdavis` `@sfackler`
2 parents 451e98e + 98096a9 commit 17ea490

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

0 commit comments

Comments
 (0)