Skip to content

Instantly share code, notes, and snippets.

@mattconnolly
Created June 10, 2016 20:32
Show Gist options
  • Save mattconnolly/dc96b7ab415e9fe0b6827deec2be535e to your computer and use it in GitHub Desktop.
Save mattconnolly/dc96b7ab415e9fe0b6827deec2be535e to your computer and use it in GitHub Desktop.
Dispatch_get_specific sees only the top queue
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
dispatch_queue_t qa = dispatch_queue_create("a", DISPATCH_QUEUE_SERIAL);
dispatch_queue_t qb = dispatch_queue_create("b", DISPATCH_QUEUE_SERIAL);
static void* key = &key;
dispatch_queue_set_specific(qa, key, (void*)1, NULL);
NSLog(@"no queue. key = %p", dispatch_get_specific(key));
dispatch_sync(qa, ^(){
NSLog(@"queue a. key = %p", dispatch_get_specific(key));
});
dispatch_sync(qb, ^(){
NSLog(@"queue b. key = %p", dispatch_get_specific(key));
});
dispatch_sync(qa, ^(){
NSLog(@"queue a. key = %p", dispatch_get_specific(key));
dispatch_sync(qb, ^(){
NSLog(@"queue b on a. key = %p", dispatch_get_specific(key));
});
});
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment