Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weaken needlessly restrictive orderings on Arc::*_count #95183

Merged
merged 1 commit into from
May 6, 2022

Conversation

ibraheemdev
Copy link
Member

@ibraheemdev ibraheemdev commented Mar 21, 2022

There is no apparent reason for these to be SeqCst. For reference, the Boost C implementation relies on acquire semantics.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 21, 2022
@ibraheemdev
Copy link
Member Author

r? @Amanieu

@Amanieu
Copy link
Member

Amanieu commented Mar 21, 2022

In theory we could even make these Relaxed since we don't promise any memory ordering and it's the user's responsibility to use an Acquire fence if they need one. However there might also be code out in the wild which relies on Acquire or SeqCst ordering here. Is there a specific reason for making this change (such as a performance concern)?

@m-ou-se
Copy link
Member

m-ou-se commented Apr 12, 2022

Cloning an Arc increments the strong counter (and cloning a Weak the weak counter) with Relaxed ordering, so if we're going to clean up these unnecssary SeqCst orderings, we should probably just make them Relaxed.

@Amanieu Amanieu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2022
@ghost
Copy link

ghost commented May 2, 2022

It looks like Relaxed also matches what C permits for std::shared_ptr<T>::use_count: https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count.

@ibraheemdev
Copy link
Member Author

ibraheemdev commented May 2, 2022

Is there a specific reason for making this change (such as a performance concern)?

Not really a specific reason, it just seemed unnecessary, and one of the library teams goals cited recently was to remove needless SeqCst orderings.

However there might also be code out in the wild which relies on Acquire or SeqCst ordering here.

Relying on Acquire seems plausible, but relying on SeqCst seems incredibly questionable and anyone doing so should really be using a fence.

@Amanieu
Copy link
Member

Amanieu commented May 6, 2022

I think this change is fine to merge, we can leave the decision to switch to Relaxed to a later PR.

@bors r

@bors
Copy link
Contributor

bors commented May 6, 2022

📌 Commit 7e93032 has been approved by Amanieu

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2022
@bors
Copy link
Contributor

bors commented May 6, 2022

⌛ Testing commit 7e93032 with merge e209e85...

@bors
Copy link
Contributor

bors commented May 6, 2022

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing e209e85 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 6, 2022
@bors bors merged commit e209e85 into rust-lang:master May 6, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 6, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e209e85): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 30, 2023
Weaken needlessly restrictive orderings on Arc::*_count

Follow up to rust-lang#95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850

I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Sep 30, 2023
Weaken needlessly restrictive orderings on Arc::*_count

Follow up to rust-lang/rust#95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850

I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
Weaken needlessly restrictive orderings on Arc::*_count

Follow up to rust-lang/rust#95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850

I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Weaken needlessly restrictive orderings on Arc::*_count

Follow up to rust-lang/rust#95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850

I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants