How can I use stderr
from the Darwin module without concurrency warnings?
Here's my code in which I attempt to protect against concurrent access with a semaphore:
import class Dispatch.DispatchSemaphore
import var Darwin.stderr
let semaphore = DispatchSemaphore(value: 1)
var stderr_safe: UnsafeMutablePointer<FILE> {
defer { semaphore.signal() }
semaphore.wait()
return stderr // warning: reference to var 'stderr'
} // is not concurrency-safe
Not sure if that's all necessary, but I'm getting this warning:
reference to var 'stderr' is not concurrency-safe because it involves shared mutable state
I tried importing with the @preconcurrency
attribute, but it doesn't seem to work as I still get that warning in addition to a remark:
'@preconcurrency' attribute on module 'Darwin' is unused
My goal is to report the progress of my terminal program to the user. The work is parallelized and I'm trying to use Darwin.fputs
, which accepts stderr
as an argument, for printing to standard error.
How can I appropriately silence this warning when compiling with -warn-concurrency
?