gpt4 book ai didi

cocoa - 默认情况下,DispatchQueue 是.serial 还是.concurrent?

转载 作者:行者123 更新时间:2023-12-03 16:05:13 24 4
gpt4 key购买 nike

这就是问题所在,就这么简单。

let serial = DispatchQueue(label: "serial", attributes: .serial)
let concurrent = DispatchQueue(label: "concurrent", attributes: .concurrent)
let q = DispatchQueue(label: "q")

我在 q 上看不到可以检查的属性(property)这会告诉我。

在 Playground 上运行 PlaygroundPage.current.needsIndefiniteExecution = true显示串行行为,但我不想依赖 Playground (有点像异步东西),或未记录的行为。

任何人都可以提供带有文档链接的明确答案吗?

最佳答案

在 Swift 3 之前,默认调度队列类型是串行 – passing nil into the attributes parameter dispatch_queue_create 将产生一个串行队列,并且我认为没有理由更改默认队列类型。尽管不幸的是我在 DispatchQueue 上找不到任何可以证实这一点的文档。

但是,looking at the source code事实证明情况确实如此:

public convenience init(
label: String,
attributes: DispatchQueueAttributes = .serial,
target: DispatchQueue? = nil)
{
...
}

尽管我总是更喜欢显式指定属性,以使我的代码更清晰并防止这种困惑。

关于cocoa - 默认情况下,DispatchQueue 是.serial 还是.concurrent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38111391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com