swift gcd串发和并发

//创建并发队列
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) ")
}

你可能感兴趣的:(swift gcd串发和并发)