美文网首页
Swift 队列的创建

Swift 队列的创建

作者: ngugg | 来源:发表于2018-09-27 22:39 被阅读3次

    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)}
    

    相关文章

      网友评论

          本文标题:Swift 队列的创建

          本文链接:https://www.haomeiwen.com/subject/zfgyoftx.html