Skip to content

Instantly share code, notes, and snippets.

@mahmudahsan
Last active August 22, 2017 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmudahsan/158309efed06501ecd87b280885d0f95 to your computer and use it in GitHub Desktop.
Save mahmudahsan/158309efed06501ecd87b280885d0f95 to your computer and use it in GitHub Desktop.
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