Skip to content

Make _swift_willThrow atomic #62349

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

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Dec 1, 2022

This change makes _swift_willThrow a C++ atomic value instead of a bare pointer. This change is necessary because the pointer can be loaded across multiple threads concurrently.

Resolves #62348.

@grynspan
Copy link
Contributor Author

grynspan commented Dec 1, 2022

@swift-ci please test

@grynspan grynspan requested a review from mikeash December 1, 2022 22:04
@grynspan
Copy link
Contributor Author

grynspan commented Dec 1, 2022

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Dec 2, 2022

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Dec 2, 2022

@swift-ci please test

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

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

LGTM.

Makes me wonder whether we do this for other callbacks, or whether we're relying on callers using them before going multithreaded or inserting their own barriers as appropriate.

@mikeash
Copy link
Contributor

mikeash commented Dec 2, 2022

We have hooks for retain/release and for the default global executor. THey're all implicitly relying on being set before multithreaded access happens. Retain/release is in practice set early in a static initializer inserted with DYLD_INSERT_LIBRARIES. The global executor hooks are up to whatever might use them, there's no specific use case there. We should probably standardize everything on something sensible like this.

@grynspan
Copy link
Contributor Author

grynspan commented Dec 3, 2022

We have hooks for retain/release and for the default global executor. THey're all implicitly relying on being set before multithreaded access happens. Retain/release is in practice set early in a static initializer inserted with DYLD_INSERT_LIBRARIES. The global executor hooks are up to whatever might use them, there's no specific use case there. We should probably standardize everything on something sensible like this.

The difference with this callback is, I think, that it's known that we set it late in execution, in another module, after other threads or tasks have already been spun up. That's why I opted to change it. I don't personally want to go around messing with those other callbacks unless somebody can show an example of them being set later in execution.

@grynspan
Copy link
Contributor Author

grynspan commented Dec 3, 2022

FWIW the overhead of making the global executor hook atomic is going to be negligible, so if it can be set late or arbitrarily, I'd agree we should take steps to make it safer.

I wouldn't dare say the overhead is negligible for retain/release, though.

@grynspan grynspan merged commit e057172 into swiftlang:main Dec 3, 2022
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.

_swift_willThrow is not atomic.
5 participants