Skip to content

Instantly share code, notes, and snippets.

@comfly
Last active August 31, 2016 21:59
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 comfly/6a9dcf7681754017b4d1f609b10bdace to your computer and use it in GitHub Desktop.
Save comfly/6a9dcf7681754017b4d1f609b10bdace to your computer and use it in GitHub Desktop.
let queue = dispatch_queue_create("QUEUE", DISPATCH_QUEUE_CONCURRENT)
var holder: Int = 10
func readSafe() -> Int {
var read: Int!
dispatch_sync(queue) {
read = holder
}
return read
}
func writeSafe(value: Int) {
dispatch_barrier_async(queue) {
holder = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment