-
-
Save fxfactorial/d6d5a6155b364f312d838044fd945751 to your computer and use it in GitHub Desktop.
This fails in iOS 9, but passes for iOS 10/11. What changed around serial/concurrent dispatch queues in iOS 10 so that this now works. Or rather, why does this not work in iOS 9?
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
- (void)testDispatchConcurrentExecutionWithNamedQueuesRaw { | |
let expectation = [self expectationWithDescription:@"Concurrent execution must happen"]; | |
let semaphore = dispatch_semaphore_create(0); | |
// global queue, concurrent | |
let attributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_DEFAULT, 0); | |
let defaultQueue = dispatch_queue_create("com.pspdfkit.default-concurrent", attributes); | |
// serial sub-queues that dispatch to concurrent queue | |
let queue1 = dispatch_queue_create("com.pspdfkit.queue1", DISPATCH_QUEUE_SERIAL); | |
dispatch_set_target_queue(queue1, defaultQueue); | |
let queue2 = dispatch_queue_create("com.pspdfkit.queue2", DISPATCH_QUEUE_SERIAL); | |
dispatch_set_target_queue(queue2, defaultQueue); | |
dispatch_async(queue1, ^{ | |
// dispatch second async operation which needs to start concurrently | |
dispatch_async(queue2, ^{ | |
dispatch_semaphore_signal(semaphore); | |
}); | |
// we cannot lock again, first have to unlock | |
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | |
[expectation fulfill]; | |
}); | |
[self waitForExpectations:@[expectation] timeout:10]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment