Created
November 24, 2015 16:11
-
-
Save jspahrsummers/af6ddfbabf3894bde981 to your computer and use it in GitHub Desktop.
[NSThread isMainThread] is probably not what you want!
This file contains 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 { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
NSLog(@"is main thread? %i", (int)[NSThread isMainThread]); | |
}); | |
}); | |
dispatch_main(); | |
} | |
return 0; | |
} |
This file contains 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
2015-11-24 16:08:39.545 main[88889:21446128] is main thread? 0 |
No problem :)
Interesting learnings from this: main thread pumps the main queue – not the other way around – since GCD only has a main queue, which by default, does nothing.
the main thread pumps the main queue – not the other way around – since GCD only has a main queue, which by default, does nothing.
What's that mean? Sorry, a bit of newb here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@adamkaplan Good point, thanks.