Created
August 23, 2016 11:44
-
-
Save andymedvedev/8c3f25cb91397aa095f2073efdb8720c to your computer and use it in GitHub Desktop.
semaphore deadlock with dispathc_async
This file contains hidden or 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
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