• Swift3GCD


    GCD的使用在Swift3中的方法

    //串行队列

    let q:DispatchQueue = DispatchQueue(label: "xiaosi")

     

    //并发队列 qos : 为 优先级别 可以不设置

    let queue = DispatchQueue(label: "com.appcoda.anotherQueue", qos: .userInitiated, attributes: .concurrent)

     

    使用最多的是异步并发

            queue.async {

                print("异步并发11111(Thread.current)")

            }

            

            queue.async {

                print("异步并发22222(Thread.current)")

            }

            

            queue.async {

                print("异步并发33333(Thread.current)")

            }

            

            queue.async {

                print("异步并发44444(Thread.current)")

            }

     

    其次是异步串行

            queue.async {

                print("异步串行11111(Thread.current)")

            }

            queue.async {

                print("异步串行2222(Thread.current)")

            }

            queue.async {

                print("异步串行4444(Thread.current)")

            }

            queue.async {

                print("异步串行5555(Thread.current)")

            }

    还有就是线程组

            let group = DispatchGroup()

     

            q.async(group: group) {

                sleep(2)

                print("异步任务3333(Thread.current)")

            }

            

            q.async(group: group) {

                sleep(2)

                print("异步任务4444(Thread.current)")

            }

            

            group.notify(queue: q) {

                print("全部做完了")

            }

            

     

     

     

  • 相关阅读:
    powershel学习(1)
    JS作用域链(转载)
    C# 对QuotedPrintable进行解码的方法
    SortedList、SortedSet、HashSet、Hashtable、Dictionary、SortedDictionary 排序/可重复排序/过滤重复排序等简单对比
    .net windows 服务中返回服务的安装目录
    c# 中图像的简单二值化处理
    windows下开多个CMD窗口多个进程输出
    生命游戏
    PowerDesigner工具简介
    七大面向对象设计原则(转)
  • 原文地址:https://www.cnblogs.com/xsiOS/p/6179474.html
Copyright © 2020-2023  润新知