diff options
| author | Miguel Ojeda <ojeda@kernel.org> | 2021-02-28 08:47:26 +0100 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2021-03-05 18:14:02 +0100 |
| commit | 98096a96c80e5488ebc0da51676835e434a751ab (patch) | |
| tree | 697b92b9808e5456b803f327646b2e31a53e0f98 /library/std/src | |
| parent | 6e2801c44eadc5cd05532a19fe1093ef6f041abe (diff) | |
| download | rust-98096a96c80e5488ebc0da51676835e434a751ab.tar.gz rust-98096a96c80e5488ebc0da51676835e434a751ab.zip | |
RWLock: Add deadlock example
Suggested in https://github.com/rust-lang/rust/pull/82596 but it was a bit too late. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sync/rwlock.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/library/std/src/sync/rwlock.rs b/library/std/src/sync/rwlock.rs index 0298f59228c..15335056d8c 100644 --- a/library/std/src/sync/rwlock.rs +++ b/library/std/src/sync/rwlock.rs @@ -25,7 +25,19 @@ use crate::sys_common::rwlock as sys; /// system's implementation, and this type does not guarantee that any /// particular policy will be used. In particular, a writer which is waiting to /// acquire the lock in `write` might or might not block concurrent calls to -/// `read`. +/// `read`, e.g.: +/// +/// <details><summary>Potential deadlock example</summary> +/// +/// ```text +/// // Thread 1 | // Thread 2 +/// let _rg = lock.read(); | +/// | // will block +/// | let _wg = lock.write(); +/// // may deadlock | +/// let _rg = lock.read(); | +/// ``` +/// </details> /// /// The type parameter `T` represents the data that this lock protects. It is /// required that `T` satisfies [`Send`] to be shared across threads and |
