swift gcd串发和并发

2018-10-13  本文已影响19人  hwhjxjs

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

上一篇下一篇

猜你喜欢

热点阅读