Instantly share code, notes, and snippets.

What would you like to do?
iOS get thread count
#include <mach/mach.h>
* @return -1 on error, else the number of threads for the current process
static int getThreadsCount() {
thread_array_t threadList;
mach_msg_type_number_t threadCount;
task_t task;
kern_return_t kernReturn = task_for_pid(mach_task_self(), getpid(), &task);
if (kernReturn != KERN_SUCCESS) {
return -1;
kernReturn = task_threads(task, &threadList, &threadCount);
if (kernReturn != KERN_SUCCESS) {
return -1;
vm_deallocate (mach_task_self(), (vm_address_t)threadList, threadCount * sizeof(thread_act_t));
return threadCount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment