Last active
March 26, 2025 20:27
-
-
Save adamvduke/1042828 to your computer and use it in GitHub Desktop.
Testing dispatch_queue_create to see if it returns a unique queue for a given name
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
| #import <Foundation/Foundation.h> | |
| int main(int argc, const char * argv[]) { | |
| @autoreleasepool { | |
| const char *name = "a_test_queue"; | |
| dispatch_queue_t queue1 = dispatch_queue_create(name, NULL); | |
| dispatch_queue_t queue2 = dispatch_queue_create(name, NULL); | |
| dispatch_async(queue1, ^{ | |
| sleep(2); | |
| NSLog(@"queue1 finishing the block" ); | |
| }); | |
| dispatch_async(queue2, ^{ | |
| sleep(2); | |
| NSLog(@"queue2 finishing the block"); | |
| }); | |
| sleep(2); | |
| BOOL same_queue = queue1 == queue2; | |
| NSLog(@"%@", same_queue ? @"YES" : @"NO"); | |
| } | |
| return 0; | |
| } |
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
| 2025-03-26 16:26:02.227326-0400 TestQueue[70102:1502794] queue2 finishing the block | |
| 2025-03-26 16:26:02.227737-0400 TestQueue[70102:1502793] queue1 finishing the block | |
| 2025-03-26 16:26:02.227886-0400 TestQueue[70102:1502297] NO | |
| Program ended with exit code: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If someone else reach this code wondering the same question... The test returns "NO"