Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite77b474

Browse files
authored
UpdateArc::try_unwrap() docs
Clarify the language wrt `race condition` not meaning `memory unsafety`.
1 parentae7f43e commite77b474

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎alloc/src/sync.rs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,18 @@ impl<T, A: Allocator> Arc<T, A> {
940940
/// This will succeed even if there are outstanding weak references.
941941
///
942942
/// 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.
952955
///
953956
/// # Examples
954957
///

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp