如何在iOS应用程序中记录正在运行的线程的数量?

问题描述:

由于我的应用程序中有大量的线程,导致SIGABRT。 我需要记录当前在我的iOS应用程序中运行的线程数。 我不想使用分析器和断点的东西。如何在iOS应用程序中记录正在运行的线程的数量?

+0

你使用GCD创建线程吗? – Bhavesh

+0

如果您暂停,使用调试器,您将能够看到调试窗口中的所有线程。或者你想在执行时记录它们吗? – Andrew

+0

如果您使用的是XCode 5,那么您可以在XCode的Debug Navigator中看到线程数量和每个线程负载的可视图表。 – Bhavesh

与此 http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/task_threads.html

#import <mach/mach_types.h> 
    #import <mach/mach_traps.h> 
    #import <mach/mach.h> 
    thread_act_array_t threads; 
    mach_msg_type_number_t thread_count; 
    task_t self = mach_task_self(); 

    /* Get a list of all threads */ 
    if (task_threads(self, &threads, &thread_count) == KERN_SUCCESS) { 
     //thread_count should be populated. 
    } 

试试吧,你还必须做一些内存管理上的一些。

+0

谢谢你!很好地工作 –