美文网首页
swift gcd串发和并发

swift gcd串发和并发

作者: hwhjxjs | 来源:发表于2018-10-13 16:04 被阅读19次

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

    相关文章

      网友评论

          本文标题:swift gcd串发和并发

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