-
-
Save valerieosmith/1ad27eed49e4af614e2144bce7f81ebb 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 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
| - (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); | |
| // This only passes if the blocks dispatched to the global queue run concurrently. | |
| // Surprisingly, this works on iOS 10/11 but fails on iOS 9. | |
| 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