Last active
August 22, 2017 06:45
-
-
Save mahmudahsan/158309efed06501ecd87b280885d0f95 to your computer and use it in GitHub Desktop.
This file contains 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