Just got to the same crash today. As far as I understand from @ktoso pitch and its subsequent proposal, this issue will be solved by implementing checkIsolated()
. However that function seems to only be used by runtimes from macOS 15+. Is this right @ktoso ? Any way to use assumeIsolated(_:)
in OSes lower than 15?
My current executor looks similar to @wadetregaskis with slight differences since I need to support macOS 14:
public import Dispatch
public extension DispatchQueue {
final class Executor: SerialExecutor {
public let queue: DispatchQueue
public init(label: ReverseDNS, qos: DispatchQoS, autoreleaseFrequency: AutoreleaseFrequency = .inherit) {
self.queue = DispatchQueue(label: label.rawValue, qos: qos, attributes: [], autoreleaseFrequency: autoreleaseFrequency, target: nil)
}
}
}
public extension DispatchQueue.Executor {
@inlinable func enqueue(_ job: consuming ExecutorJob) {
let unownedJob = UnownedJob(consume job)
let unownedSerialExecutor = self.asUnownedSerialExecutor()
#if compiler(>=6.0)
if #available(macOS 15, *) {
let unownedTaskExecutor = self.asUnownedTaskExecutor()
return queue.async {
unownedJob.runSynchronously(isolatedTo: unownedSerialExecutor, taskExecutor: unownedTaskExecutor)
}
}
#else
queue.async {
unownedJob.runSynchronously(on: unownedSerialExecutor)
}
#endif
}
@inlinable func asUnownedSerialExecutor() -> UnownedSerialExecutor {
UnownedSerialExecutor(ordinary: self)
}
}
#if compiler(>=6.0)
@available(macOS 15, *)
extension DispatchQueue.Executor: TaskExecutor {
@inlinable public func asUnownedTaskExecutor() -> UnownedTaskExecutor {
UnownedTaskExecutor(ordinary: self)
}
@inlinable public func checkIsolated() {
dispatchPrecondition(condition: .onQueue(queue))
}
}
#endif
Is there any way to backdeploy TaskExecutor
s as well?