-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathThread.h
More file actions
45 lines (40 loc) · 1.42 KB
/
Thread.h
File metadata and controls
45 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <pthread.h>
static void showThreadList(void) {
char name[256];
mach_msg_type_number_t count;
thread_act_array_t list;
kern_return_t kret;
kret = task_threads(target_task, &list, &count);
if (kret == KERN_SUCCESS) {
for (int i = 0; i < count; ++i) {
pthread_t pt = pthread_from_mach_thread_np(list[i]);
if (pt) {
name[0] = '\0';
int rc = pthread_getname_np(pt, name, sizeof name);
printf("Thread %u: getname returned %d: %s\n", list[i], rc, name);
} else {
printf("Thread %u: no pthread found\n", list[i]);
}
}
}else{
printf("task_threads() failed with message %s!\n",mach_error_string(kret));
}
}
void suspendThread(thread_t target_thread){
kern_return_t kret;
kret = thread_suspend(target_thread);
if (kret == KERN_SUCCESS) {
printf("thread_suspend() succeed with message %s!\n",mach_error_string(kret));
}else{
printf("task_threads() failed with message %s!\n",mach_error_string(kret));
}
}
void resumeThread(thread_t target_thread){
kern_return_t kret;
kret = thread_resume(target_thread);
if (kret == KERN_SUCCESS) {
printf("thread_resume() resume with message %s!\n",mach_error_string(kret));
}else{
printf("task_threads() failed with message %s!\n",mach_error_string(kret));
}
}