@@ -940,15 +940,18 @@ impl<T, A: Allocator> Arc<T, A> { |
|
|
940 |
940 |
/// This will succeed even if there are outstanding weak references. |
941 |
941 |
/// |
942 |
942 |
/// It is strongly recommended to use [`Arc::into_inner`] instead if you don't |
943 |
|
- /// want to keep the `Arc` in the [`Err`] case. |
944 |
|
- /// Immediately dropping the [`Err`] payload, like in the expression |
945 |
|
- /// `Arc::try_unwrap(this).ok()`, can still cause the strong count to |
946 |
|
- /// drop to zero and the inner value of the `Arc` to be dropped: |
947 |
|
- /// For instance if two threads each execute this expression in parallel, then |
948 |
|
- /// there is a race condition. The threads could first both check whether they |
949 |
|
- /// have the last clone of their `Arc` via `Arc::try_unwrap`, and then |
950 |
|
- /// both drop their `Arc` in the call to [`ok`][`Result::ok`], |
951 |
|
- /// taking the strong count from two down to zero. |
|
943 |
+ /// keep the `Arc` in the [`Err`] case. |
|
944 |
+ /// Immediately dropping the [`Err`]-value, as the expression |
|
945 |
+ /// `Arc::try_unwrap(this).ok()` does, can cause the strong count to |
|
946 |
+ /// drop to zero and the inner value of the `Arc` to be dropped. |
|
947 |
+ /// For instance, if two threads execute such an expression in parallel, |
|
948 |
+ /// there is a race condition without the possibility of unsafety: |
|
949 |
+ /// The threads could first both check whether they own the last instance |
|
950 |
+ /// in `Arc::try_unwrap`, determine that they both do not, and then both |
|
951 |
+ /// discard and drop their instance in the call to [`ok`][`Result::ok`]. |
|
952 |
+ /// In this scenario, the value inside the `Arc` is safely destroyed |
|
953 |
+ /// by exactly one of the threads, but neither thread will ever be able |
|
954 |
+ /// to use the value. |
952 |
955 |
/// |
953 |
956 |
/// # Examples |
954 |
957 |
/// |