swift 创建的队列默认为串行队列
let queue = DispatchQueue(label: "hahha")
// let queue = DispatchQueue(label: "haha", attributes: .concurrent)
for _ in 1...10 {
queue.async {
print("111---" + "\(Thread.current)")
}
}
for _ in 1...10 {
queue.async {
print("222---" + "\(Thread.current)")
}
}
for _ in 1...10 {
queue.async {
print("333---" + "\(Thread.current)")
}
}
运行结果:
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
111---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
222---<NSThread: 0x600000279b40>{number = 3, name = (null)}
333---<NSThread: 0x600000279b40>{number = 3, name = (null)}
333---<NSThread: 0x600000279b40>{number = 3, name = (null)}
333---<NSThread: 0x600000279b40>{number = 3, name = (null)}
网友评论