//创建并发队列
let concurrentQueue = DispatchQueue(label: "mkiltech.com",attributes: .concurrent)
//创建串行队列
let serialQueue = DispatchQueue(label: "mkiltech.com")
//串行异步
serialQueue.async {
sleep(2)
print("serialTask 1" + "(Thread.current) ")
}
serialQueue.async {
print("serialTask 2" + "(Thread.current) ")
}
//并发异步
concurrentQueue.async {
sleep(2)
print("concurrentTask 1" + "(Thread.current) ")
}
concurrentQueue.async {
print("concurrentTask 2" + "(Thread.current) ")
}
网友评论