Skip to content

Instantly share code, notes, and snippets.

@cooler333
Created May 18, 2020 12:15
Show Gist options
  • Save cooler333/79ca55c6724c87926b841f490fda71ae to your computer and use it in GitHub Desktop.
Save cooler333/79ca55c6724c87926b841f490fda71ae to your computer and use it in GitHub Desktop.
import Foundation
var count = 0
let group = DispatchGroup()
group.enter()
let thread1 = Thread {
for _ in 0...9999 {
count += 1
}
group.leave()
}
group.enter()
let thread2 = Thread {
for _ in 0...9999 {
count += 1
}
group.leave()
}
thread1.start()
thread2.start()
group.notify(queue: DispatchQueue.global()) {
print(count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment