Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法找到与“dispatch_get_main_queue()”关联的线程 ID?
在主队列上评估的任何块都将在与其关联的线程上评估,因此您可以通过询问此类块正在评估的线程来获取该线程的 ID:
#import <mach/mach_init.h> __block mach_port_t mainThreadID; dispatch_async(dispatch_get_main_queue(), ^{ mainThreadID = mach_thread_self(); });
(Amach_port_t实际上只是一个无符号整数。)
mach_port_t