开发者

thread id of dispatch_get_main_queue()

Is there a开发者_StackOverflow社区 way to find the thread id that is associated with 'dispatch_get_main_queue()'?


Any block evaluated on the main queue will evaluate on the thread it is associated with, so you can get the ID of that thread by asking what thread such a block is evaluating on:

#import <mach/mach_init.h>

__block mach_port_t mainThreadID;
dispatch_async(dispatch_get_main_queue(), ^{
    mainThreadID = mach_thread_self();
});

(A mach_port_t is really just an unsigned int.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜