Skip to content

Add hint::spin_loop() into Atomic*::*update()#159121

Open
im-0 wants to merge 1 commit into
rust-lang:mainfrom
im-0:add-spin-loop-into-atomic-update
Open

Add hint::spin_loop() into Atomic*::*update()#159121
im-0 wants to merge 1 commit into
rust-lang:mainfrom
im-0:add-spin-loop-into-atomic-update

Conversation

@im-0

@im-0 im-0 commented Jul 11, 2026

Copy link
Copy Markdown

Atomic*::update() and Atomic*::try_update() are implemented using a CAS loop and thus spin loop hint seems appropriate here.

Question: are there any relevant benchmarks to run to check that this patch does not regress anything? For example, I see that try_update() is used to implement RwLock. Are there any benchmarks for RwLock?

`Atomic*::update()` and `Atomic*::try_update()` are implemented using
a CAS loop and thus spin loop hint seems appropriate here.
@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 Jul 11, 2026
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @aapoalas (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from 6 candidates

@joboet

joboet commented Jul 11, 2026

Copy link
Copy Markdown
Member

Thanks for the pull request!

I'd argue against this: the CAS will only fail if the value is concurrently being changed but hint::spin_loop() is intended for cases where the value is repeatedly loaded to check whether some condition has been fulfilled, i.e. the thread is busy-waiting.

That's also why e.g. compare_exchange on targets that only have LL/SC instructions (like ARM) doesn't use the yield instruction, even though the value may be repeatedly loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants