Skip to content

Make Reference concurrency safe - #880

Merged
natecook1000 merged 2 commits into
mainfrom
fix/threadsafe-reference
Sep 29, 2026
Merged

natecook1000 merged 2 commits into
mainfrom
fix/threadsafe-reference

Conversation

@natecook1000

@natecook1000 natecook1000 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

The Reference type in the RegexBuilder module uses an unprotected static var counter: Int as a source of unique IDs, which can fail due to a race when used in concurrent contexts. This switches to using a new AtomicCounter type, which uses an (~internal) standard library entry point for loading/incrementing an atomic integer.

Note that this only shows up as a bug when the race leads to multiple references inside a single builder Regex with identical IDs, which is considerably more rare than the race itself, so the last test in ReferenceConcurrencyTests.swift only fails occasionally when run against the existing version.

rdar://180971141

@natecook1000
natecook1000 requested a review from Azoy September 23, 2026 20:46
Comment thread Sources/_StringProcessing/Utility/AtomicCounter.swift Outdated

@Azoy Azoy left a comment

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.

Looks good to me 👍

@natecook1000

Copy link
Copy Markdown
Member Author

@swift-ci Please test Linux platform

@natecook1000
natecook1000 merged commit 0a2de4b into main Sep 29, 2026
24 of 25 checks passed
@natecook1000
natecook1000 deleted the fix/threadsafe-reference branch September 29, 2026 22:21
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.

2 participants