Hi guys,
I have this piece of code that compiles cleanly under Swift 6 on macOS:
private static let serviceQueueLabel = "label"
private static let serviceQueueSpecificKey = DispatchSpecificKey<String>()
private static let serviceQueueSpecificValue = "anything"
internal static let serviceQueue = ({ () -> DispatchQueue in
let queue = DispatchQueue(label: serviceQueueLabel, qos: .userInteractive)
queue.setSpecific(key: serviceQueueSpecificKey, value: serviceQueueSpecificValue)
return queue
})()
Note that examples like these in the past used UnsafeMutablePointer
as queue specific value, but that does not compile under Swift 6 because (from Dispatch
on macOS:
final public class DispatchSpecificKey<T> {
public init()
}
extension DispatchSpecificKey : Sendable where T : Sendable {}
The same code does not compile under Linux with the following error:
error: static property 'serviceQueueSpecificKey' is not concurrency-safe because non-'Sendable' type 'DispatchSpecificKey<String>' may have shared mutable state
Is this a known issue? If not where can I report this problem?
Martin