1 | [[NSThread currentThread] isMainThread] ? NSLog(@"MAIN THREAD") : NSLog(@"NOT MAIN THREAD"); |
保证主线程运行
1 | void ensureOnMainQueue(void (^block)(void)) { |
1 | if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) { // do something in main thread |
主线程中也不绝对安全的 UI 操作
http://www.jianshu.com/p/d15f4b37b0f2
https://stackoverflow.com/questions/3546539/check-whether-or-not-the-current-thread-is-the-main-thread
https://stackoverflow.com/questions/17475002/get-current-dispatch-queue