Skip to content

Instantly share code, notes, and snippets.

@adamvduke
Last active March 26, 2025 20:27
Show Gist options
  • Select an option

  • Save adamvduke/1042828 to your computer and use it in GitHub Desktop.

Select an option

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
#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;
}
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
@dcordero

Copy link
Copy Markdown

If someone else reach this code wondering the same question... The test returns "NO"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment