开发者

thread id of dispatch_get_main_queue()

开发者 https://www.devze.com 2023-02-15 17:30 出处:网络
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 wi

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

精彩评论

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