Skip to content

Instantly share code, notes, and snippets.

@andymedvedev
Created August 23, 2016 11:44
Show Gist options
  • Save andymedvedev/8c3f25cb91397aa095f2073efdb8720c to your computer and use it in GitHub Desktop.
Save andymedvedev/8c3f25cb91397aa095f2073efdb8720c to your computer and use it in GitHub Desktop.
semaphore deadlock with dispathc_async
func waitFunc(completion:(Bool) -> Void ) {
dispatch_async(dispatch_get_main_queue()) {
print("1")
sleep(1)
completion(true)
}
}
func Test() {
for i in 0..<5 {
print("another")
let semaphore = dispatch_semaphore_create(0)
waitFunc() { finished in
print("FINISHED = \(finished)")
dispatch_semaphore_signal(semaphore)
}
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment