Created
November 28, 2017 03:06
-
-
Save mahmudahsan/8bfc108dfb6f5ed99d6a18a053bc0a35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
//to run serial queue in playground always make the following true | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let mainQueue = DispatchQueue.main | |
let globalQueue = DispatchQueue.global() | |
let serialQueue = DispatchQueue(label: "net.ithinkdiff.app") | |
let concurQueue = DispatchQueue(label: "net.ithinkdiff.app.concurr", attributes: .concurrent) | |
func workInConcurrently(_ num: Int, _ sleepTime: Int){ | |
print("Concurrent Work \(num)") | |
} | |
func workInSerially(num:Int){ | |
print("Serial Work \(num)") | |
sleep(1) | |
} | |
globalQueue.async { | |
workInConcurrently(1, 5) | |
workInConcurrently(2, 1) | |
workInConcurrently(3, 3) | |
workInConcurrently(4, 1) | |
} | |
mainQueue.async { | |
workInSerially(num: 1) | |
workInSerially(num: 2) | |
workInSerially(num: 3) | |
workInSerially(num: 4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment