Skip to content

[doc] Atomic.add, .subtract: Add note on atomic codegen #78799

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

Merged
merged 1 commit into from
May 17, 2025

Conversation

lorentey
Copy link
Member

Add this note to the doc string of Atomic.add and Atomic.subtract, highlighting a subtle aspect that tends to surprise folks who're porting code from C/C++:

The need to check for overflow means that this operation is typically compiled into a compare-exchange loop. For use cases that require a direct atomic addition, see the wrappingAdd operation: it avoids the loop, but in exchange it allows silent wraps on overflow.

@lorentey lorentey requested a review from Azoy January 22, 2025 00:02
@lorentey lorentey requested a review from a team as a code owner January 22, 2025 00:02
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

@swift-ci smoke test linux platform

@lorentey lorentey marked this pull request as draft January 23, 2025 17:49
@lorentey lorentey marked this pull request as ready for review February 1, 2025 02:15
@lorentey
Copy link
Member Author

lorentey commented Feb 1, 2025

@swift-ci smoke test

@lorentey
Copy link
Member Author

@swift-ci test linux platform

@lorentey
Copy link
Member Author

@swift-ci test linux platform

@lorentey lorentey merged commit 02adf95 into swiftlang:main May 17, 2025
5 checks passed
@lorentey lorentey deleted the note-cas-loops branch May 17, 2025 02:05
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants