-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Cannot use Glibc.stdout/stderr with Concurrency (error: reference to var 'stderr' is not concurrency-safe because it involves shared mutable state) #77866
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
Comments
any updates ? ubuntu swift 6.0.3 // GlibC Linux platforms
import Glibc
private let stdoutLock = NSLock()
nonisolated(unsafe)
func configureStdout() {
stdoutLock.lock()
defer { stdoutLock.unlock() }
setbuf(stdout, nil)
}
configureStdout() I've tried everything, nothing works error: reference to var 'stdout' is not concurrency-safe because it involves shared mutable state |
@nerzh For now, use
and it'll work just fine |
@weissi thank you for fast answer 🤝 |
I suspect I'm missing something, but switching adding
This still leaves me with:
Which is a little confusing. I imagine I'm holding it wrong. |
@jbmorley Well hello friend! Are you maybe also See some issues/PRs here:
Essentially, you need to put |
@weissi Hi! 👋🏻 Thanks for taking the time to give me some more thoughts. Turns out I was indeed also importing Foundation. I'd put the Glibc import above everything else just in case, but at no point did it occur to me that Foundation would also be importing Glibc. Of course it is. 🤦🏻 Oh well. All working now! Thank you again. |
### Motivation: The non-`Darwin` libcs don't have the correct concurrency annotations. But due to these Swift bugs, it's important that the _first_ importer uses `@preconcurrency`: - swiftlang/swift#79414 - swiftlang/swift#77866 ### Modifications: Much like the Foundation (& corelibs) PRs such as swiftlang/swift-foundation#1175 , use `@preconcurrency import` for the non-`Darwin` libcs. ### Result: Fewer bad warnings/errors in user code.
Description
Getting a compiler error when using Glibc.stdout/stderr with Concurrency
Reproduction
Expected behavior
compiles fine
Environment
6.0.2
Additional information
No response
The text was updated successfully, but these errors were encountered: