Skip to content

Use Ordering::Acquire in Arc::try_unwrap - #150709

Closed
cramertj wants to merge 1 commit into
rust-lang:mainfrom
cramertj:acquire
Closed

cramertj wants to merge 1 commit into
rust-lang:mainfrom
cramertj:acquire

Conversation

@cramertj

@cramertj cramertj commented Jan 5, 2026

Copy link
Copy Markdown
Member

After unwrapping the Arc, the reader should observe all writes that occurred before the penultimate refcount was dropped. Note that this is consistent with the ordering used in Arc::is_unique and Arc::make_mut, both of which have similar function.

See also discussion on #150631 (comment)
r? @Mark-Simulacrum

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 5, 2026
@rust-log-analyzer

This comment has been minimized.

After unwrapping the Arc, the reader should observe all writes that
occurred before the penultimate refcount was dropped. Note that
this is consistent with the ordering used in `Arc::is_unique`
and `Arc::make_mut`, both of which have similar function.
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator

📌 Commit f975271 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 5, 2026
Comment thread library/alloc/src/sync.rs
// of the penultimate `Arc`, allowing the resulting value to contain
// all modifications that may have happened due to that copy of the
// `Arc`.
if this.inner().strong.compare_exchange(1, 0, Acquire, Relaxed).is_err() {

@tmiasko tmiasko Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you perhaps missed the fact that the success path already contains acquire fence?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, yes! Thank you.

@cramertj cramertj closed this Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants