简体   繁体   English

dispatch_get_main_queue()的线程ID

[英]thread id of dispatch_get_main_queue()

有没有办法找到与“ dispatch_get_main_queue()”相关联的线程ID?

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: 在主队列上评估的任何块都将在与其关联的线程上进行评估,因此您可以通过询问该块在哪个线程上进行评估来获取该线程的ID:

#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.) mach_port_t实际上只是一个无符号的int。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 主线程中的di​​spatch_get_main_queue() - dispatch_get_main_queue() in main thread dispatch_get_main_queue的奇怪行为 - Strange behavior of dispatch_get_main_queue dispatch_async(dispatch_get_main_queue(),^ {}); 从iOS7背景线程慢 - dispatch_async(dispatch_get_main_queue(), ^{}); from Background Thread slow on iOS7 使用dispatch_get_main_queue()是否意味着我的代码将在主线程上? - Does using dispatch_get_main_queue() mean that my code will be on the main thread? “阻止”主线程(dispatch_get_main_queue())和(或不)定期运行 currentRunLoop - 有什么区别? - "Block" main thread (dispatch_get_main_queue()) and (or not) run currentRunLoop periodically - what is the difference? dispatch_sync(dispatch_get_main_queue()UI古怪 - dispatch_sync(dispatch_get_main_queue() UI weirdness 在这种情况下,dispatch_async(dispatch_get_main_queue(),...)是否必要? - Is dispatch_async(dispatch_get_main_queue(), …) necessary in this case? dispatch_get_main_queue块中的代码 - code inside dispatch_get_main_queue block IOS dispatch_get_main_queue()被多次调用 - IOS dispatch_get_main_queue() is called multiple times 包含dispatch_get_main_queue(GCD)的标准库 - Standard library containing dispatch_get_main_queue (GCD)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM