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

Adopt noasync for ThreadSpecificVariable #2206

Merged
merged 3 commits into from
Jun 30, 2022

Conversation

dnadoba
Copy link
Member

@dnadoba dnadoba commented Jun 28, 2022

Mark ThreadSpecificVariable.currentValue as not available from asynchronous context.

Motivation:

From SE-0340 (Unavailable From Async Attribute):

The Swift concurrency model allows tasks to resume on different threads from the one they were suspended on. For this reason, API that relies on thread-local storage, locks, mutexes, and semaphores, should not be used across suspension points.

Modifications:

add @available(*, noasync) to ThreadSpecificVariable.currentValue in Swift 5.7+

Result:

Prevent accidental misuse of ThreadSpecificVariable

Note: The noasync diagnostics in the latest Swift 5.7 nightly compiler emits errors instead of warnings but this is already fixed and will be part of the next 5.7 nightly toolchain. swiftlang/swift#59748

@dnadoba dnadoba added the 🔼 needs-minor-version-bump For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0 label Jun 28, 2022
Sources/NIOPosix/Thread.swift Show resolved Hide resolved
Sources/NIOPosix/Thread.swift Outdated Show resolved Hide resolved
@dnadoba
Copy link
Member Author

dnadoba commented Jun 29, 2022

@swift-nio-bot test this please

1 similar comment
@Lukasa
Copy link
Contributor

Lukasa commented Jun 30, 2022

@swift-nio-bot test this please

@dnadoba dnadoba merged commit e650ac1 into apple:main Jun 30, 2022
@dnadoba dnadoba deleted the dn-thread-specific-variable-noasync branch June 30, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔼 needs-minor-version-bump For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants