Created
April 23, 2013 13:48
-
-
Save McZonk/5443691 to your computer and use it in GitHub Desktop.
Dispatch Behavior
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
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_block_t block = ^{ | |
int a = 5; | |
NSLog(@"%p = %d", &a, a); | |
}; | |
block(); | |
dispatch_async(queue, block); | |
dispatch_async(queue, ^{ | |
block(); | |
}); | |
dispatch_async(queue, ^{ | |
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ | |
block(); | |
}); | |
}); | |
sleep(10); | |
} | |
return 0; | |
} | |
/* | |
OUTPUT: | |
2013-04-23 15:47:37.546 BlockTest[29703:303] 0x7fff5fbff86c = 5 | |
2013-04-23 15:47:37.548 BlockTest[29703:1a03] 0x100780e5c = 5 | |
2013-04-23 15:47:37.548 BlockTest[29703:1803] 0x100580e7c = 5 | |
2013-04-23 15:47:37.548 BlockTest[29703:1b03] 0x1022a5dcc = 5 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment