zoukankan      html  css  js  c++  java
  • 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("全部做完了")

            }

            

     

     

     

  • 相关阅读:
    xcode 查看stastic
    erlang 游戏服务器开发
    同一世界服务器架构--Erlang游戏服务器
    理解Erlang/OTP
    使用SecureCRT连接AWS的EC2
    redis单主机多实例
    Redis命令总结
    [redis] redis配置文件redis.conf的详细说明
    [转至云风的博客]开发笔记 (2) :redis 数据库结构设计
    Redis 集群方案
  • 原文地址:https://www.cnblogs.com/xsiOS/p/6179474.html
Copyright © 2011-2022 走看看